Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c617e33

Browse files
committed
do not validate passwords when the hash is null
1 parent 30294c4 commit c617e33

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke
6161
throw new BadCredentialsException('The presented password cannot be empty.');
6262
}
6363

64-
if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) {
64+
if (null === $user->getPassword() || !$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) {
6565
throw new BadCredentialsException('The presented password is invalid.');
6666
}
6767
}

src/Symfony/Component/Security/Core/Encoder/UserPasswordEncoder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function encodePassword(UserInterface $user, $plainPassword)
4242
*/
4343
public function isPasswordValid(UserInterface $user, $raw)
4444
{
45+
if (null === $user->getPassword()) {
46+
return false;
47+
}
48+
4549
$encoder = $this->encoderFactory->getEncoder($user);
4650

4751
return $encoder->isPasswordValid($user->getPassword(), $raw, $user->getSalt());

src/Symfony/Component/Security/Core/Validator/Constraints/UserPasswordValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function validate($password, Constraint $constraint)
5353

5454
$encoder = $this->encoderFactory->getEncoder($user);
5555

56-
if (!$encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) {
56+
if (null === $user->getPassword() || !$encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) {
5757
$this->context->addViolation($constraint->message);
5858
}
5959
}

0 commit comments

Comments
 (0)