Skip to content

Commit

Permalink
[11.x] Rehash user passwords when logging in once (#50843)
Browse files Browse the repository at this point in the history
* Rehash user passwords when validating credentials

* Update SessionGuard.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
axlon and taylorotwell authored Mar 29, 2024
1 parent c8dfb41 commit a6de7c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Auth/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ public function once(array $credentials = [])
$this->fireAttemptEvent($credentials);

if ($this->validate($credentials)) {
$this->rehashPasswordIfRequired($this->lastAttempted, $credentials);

$this->setUser($this->lastAttempted);

return true;
Expand Down
2 changes: 2 additions & 0 deletions tests/Auth/AuthGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ public function testLoginOnceSetsUser()
});
$guard->getProvider()->shouldReceive('retrieveByCredentials')->once()->with(['foo'])->andReturn($user);
$guard->getProvider()->shouldReceive('validateCredentials')->once()->with($user, ['foo'])->andReturn(true);
$guard->getProvider()->shouldReceive('rehashPasswordIfRequired')->with($user, ['foo'])->once();
$guard->shouldReceive('setUser')->once()->with($user);
$this->assertTrue($guard->once(['foo']));
}
Expand All @@ -637,6 +638,7 @@ public function testLoginOnceFailure()
});
$guard->getProvider()->shouldReceive('retrieveByCredentials')->once()->with(['foo'])->andReturn($user);
$guard->getProvider()->shouldReceive('validateCredentials')->once()->with($user, ['foo'])->andReturn(false);
$guard->getProvider()->shouldNotReceive('rehashPasswordIfRequired');
$this->assertFalse($guard->once(['foo']));
}

Expand Down

0 comments on commit a6de7c6

Please sign in to comment.