File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ the user::
3434 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
3535 use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
3636 use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
37+ use Symfony\Component\Security\Core\Exception\BadCredentialsException;
3738 use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
3839 use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
3940 use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -58,7 +59,20 @@ the user::
5859 throw new CustomUserMessageAuthenticationException('Invalid username or password');
5960 }
6061
61- $isPasswordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());
62+ $currentUser = $token->getUser();
63+
64+ if ($currentUser instanceof UserInterface) {
65+ if ($currentUser->getPassword() !== $user->getPassword()) {
66+ throw new BadCredentialsException('The credentials were changed from another session.');
67+ }
68+ } else {
69+ if ('' === ($givenPassword = $token->getCredentials())) {
70+ throw new BadCredentialsException('The given password cannot be empty.');
71+ }
72+ if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $givenPassword, $user->getSalt())) {
73+ throw new BadCredentialsException('The given password is invalid.');
74+ }
75+ }
6276
6377 if ($isPasswordValid) {
6478 $currentHour = date('G');
You can’t perform that action at this time.
0 commit comments