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::
2828 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2929 use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
3030 use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
31+ use Symfony\Component\Security\Core\Exception\BadCredentialsException;
3132 use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
3233 use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
3334 use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -52,7 +53,20 @@ the user::
5253 throw new CustomUserMessageAuthenticationException('Invalid username or password');
5354 }
5455
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+ }
5670
5771 if ($isPasswordValid) {
5872 $currentHour = date('G');
You can’t perform that action at this time.
0 commit comments