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

Skip to content

Commit cb429cd

Browse files
author
Robin Chalas
committed
bug #34779 [Security] do not validate passwords when the hash is null (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [Security] do not validate passwords when the hash is null | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #34775 | License | MIT | Doc PR | Commits ------- 5699cb2 do not validate passwords when the hash is null
2 parents 3b42ca9 + 5699cb2 commit cb429cd

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
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/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider;
1616
use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder;
1717
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
18+
use Symfony\Component\Security\Core\User\User;
1819

1920
class DaoAuthenticationProviderTest extends TestCase
2021
{
@@ -151,7 +152,7 @@ public function testCheckAuthenticationWhenCredentialsAre0()
151152

152153
$method->invoke(
153154
$provider,
154-
$this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock(),
155+
new User('username', 'password'),
155156
$token
156157
);
157158
}
@@ -175,7 +176,7 @@ public function testCheckAuthenticationWhenCredentialsAreNotValid()
175176
->willReturn('foo')
176177
;
177178

178-
$method->invoke($provider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock(), $token);
179+
$method->invoke($provider, new User('username', 'password'), $token);
179180
}
180181

181182
public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChanged()
@@ -247,7 +248,7 @@ public function testCheckAuthentication()
247248
->willReturn('foo')
248249
;
249250

250-
$method->invoke($provider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock(), $token);
251+
$method->invoke($provider, new User('username', 'password'), $token);
251252
}
252253

253254
protected function getSupportedToken()

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)