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 @@ -28,6 +28,7 @@ the user::
28
28
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
29
29
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
30
30
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
31
+ use Symfony\Component\Security\Core\Exception\BadCredentialsException;
31
32
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
32
33
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
33
34
use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -52,7 +53,20 @@ the user::
52
53
throw new CustomUserMessageAuthenticationException('Invalid username or password');
53
54
}
54
55
55
- $isPasswordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());
56
+ $currentUser = $token->getUser();
57
+
58
+ if ($currentUser instanceof UserInterface) {
59
+ if ($currentUser->getPassword() !== $user->getPassword()) {
60
+ throw new BadCredentialsException('The credentials were changed from another session.');
61
+ }
62
+ } else {
63
+ if ('' === ($givenPassword = $token->getCredentials())) {
64
+ throw new BadCredentialsException('The given password cannot be empty.');
65
+ }
66
+ if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $givenPassword, $user->getSalt())) {
67
+ throw new BadCredentialsException('The given password is invalid.');
68
+ }
69
+ }
56
70
57
71
if ($isPasswordValid) {
58
72
$currentHour = date('G');
You can’t perform that action at this time.
0 commit comments