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::
34
34
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
35
35
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
36
36
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
37
+ use Symfony\Component\Security\Core\Exception\BadCredentialsException;
37
38
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
38
39
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
39
40
use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -58,7 +59,20 @@ the user::
58
59
throw new CustomUserMessageAuthenticationException('Invalid username or password');
59
60
}
60
61
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
+ }
62
76
63
77
if ($isPasswordValid) {
64
78
$currentHour = date('G');
You can’t perform that action at this time.
0 commit comments