Skip to content

Commit 4f57a44

Browse files
committed
Merge remote-tracking branch 'symfony-se/maker-bundle-userenum' into main
* symfony-se/maker-bundle-userenum: [MakerBundle] Prevent user enumeration
2 parents 060ce03 + 64c284b commit 4f57a44

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/Resources/skeleton/authenticator/LoginFormAuthenticator.tpl.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1010
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1111
<?= $user_needs_encoder ? "use Symfony\\Component\\Security\\Core\\Encoder\\UserPasswordEncoderInterface;\n" : null ?>
12-
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
1312
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
13+
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
1414
use Symfony\Component\Security\Core\Security;
1515
use Symfony\Component\Security\Core\User\UserInterface;
1616
use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -73,8 +73,7 @@ public function getUser($credentials, UserProviderInterface $userProvider)
7373
\$user = \$userProvider->loadUserByUsername(\$credentials['$username_field']);\n"; ?>
7474

7575
if (!$user) {
76-
// fail authentication with a custom error
77-
throw new CustomUserMessageAuthenticationException('<?= ucfirst($username_field_label) ?> could not be found.');
76+
throw new UsernameNotFoundException('<?= ucfirst($username_field_label) ?> could not be found.');
7877
}
7978

8079
return $user;

tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/src/Security/LoginFormAuthenticator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1010
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1111
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
12-
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
1312
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
13+
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
1414
use Symfony\Component\Security\Core\Security;
1515
use Symfony\Component\Security\Core\User\UserInterface;
1616
use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -70,7 +70,7 @@ public function getUser($credentials, UserProviderInterface $userProvider)
7070
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $credentials['email']]);
7171

7272
if (!$user) {
73-
throw new CustomUserMessageAuthenticationException('Email could not be found.');
73+
throw new UsernameNotFoundException('Email could not be found.');
7474
}
7575

7676
return $user;

0 commit comments

Comments
 (0)