8000 bug #41008 [Security] Do not try to rehash null-passwords (tjveldhuizen) · symfony/symfony@56b664e · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 56b664e

Browse files
committed
bug #41008 [Security] Do not try to rehash null-passwords (tjveldhuizen)
This PR was merged into the 5.2 branch. Discussion ---------- [Security] Do not try to rehash null-passwords | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #41005 | License | MIT | Doc PR | - Make sure no exception occurs when a passwordless user logs in. Commits ------- a2a944e [Security] Do not try to rehash null-passwords
2 parents 92b6458 + a2a944e commit 56b664e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Component/Security/Http/EventListener/PasswordMigratingListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public function onLoginSuccess(LoginSuccessEvent $event): void
5050
}
5151

5252
$user = $passport->getUser();
53+
if (null === $user->getPassword()) {
54+
return;
55+
}
56+
5357
$passwordEncoder = $this->encoderFactory->getEncoder($user);
5458
if (!$passwordEncoder->needsRehash($user->getPassword())) {
5559
return;

src/Symfony/Component/Security/Http/Tests/EventListener/PasswordMigratingListenerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ public function testUpgradeWithoutUpgrader()
108108
$this->listener->onLoginSuccess($event);
109109
}
110110

111+
public function testUserWithoutPassword()
112+
{
113+
$this->user = new User('test', null);
114+
115+
$this->encoderFactory->expects($this->never())->method('getEncoder');
116+
117+
$event = $this->createEvent(new SelfValidatingPassport(new UserBadge('test', function () { return $this->user; }), [new PasswordUpgradeBadge('pa$$word')]));
118+
$this->listener->onLoginSuccess($event);
119+
}
120+
111121
private function createPasswordUpgrader()
112122
{
113123
return $this->createMock(MigratingUserProvider::class);

0 commit comments

Comments
 (0)
0