8000 do not validate passwords when the hash is null · symfony/symfony@b0172e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit b0172e0

Browse files
committed
do not validate passwords when the hash is null
1 parent 3b42ca9 commit b0172e0

File tree

4 files changed

+12
-5
lines changed

4 files 8000 changed

+12
-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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider;
16+
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
1617
use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder;
1718
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
19+
use Symfony\Component\Security\Core\User\User;
20+
use Symfony\Component\Security\Core\User\UserInterface;
1821

1922
class DaoAuthenticationProviderTest extends TestCase
2023
{
@@ -151,7 +154,7 @@ public function testCheckAuthenticationWhenCredentialsAre0()
151154

152155
$method->invoke(
153156
$provider,
154-
$this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock(),
157+
new User('username', 'password'),
155158
$token
156159
);
157160
}
@@ -175,7 +178,7 @@ public function testCheckAuthenticationWhenCredentialsAreNotValid()
175178
->willReturn('foo')
176179
;
177180

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

181184
public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChanged()
@@ -247,7 +250,7 @@ public function testCheckAuthentication()
247250
->willReturn('foo')
248251
;
249252

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

253256
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)
0