-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require the correct password to rehash it
- Loading branch information
Showing
2 changed files
with
37 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -573,6 +573,26 @@ protected function cycleRememberToken(AuthenticatableContract $user) | |
$this->provider->updateRememberToken($user, $token); | ||
} | ||
|
||
/** | ||
* Rehash the user's password. | ||
* | ||
* @param string $password | ||
* @param string $attribute | ||
* @return bool|null | ||
* | ||
* @throws AuthenticationException If the password is invalid. | ||
*/ | ||
protected function rehashUserPassword($password, $attribute) | ||
{ | ||
if (! Hash::check($password, $this->user()->$attribute)) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cgaube
|
||
throw new AuthenticationException('Password mismatch.'); | ||
} | ||
|
||
return tap($this->user()->forceFill([ | ||
$attribute => Hash::make($password), | ||
]))->save(); | ||
} | ||
|
||
/** | ||
* Invalidate other sessions for the current user. | ||
* | ||
|
@@ -588,9 +608,7 @@ public function logoutOtherDevices($password, $attribute = 'password') | |
return; | ||
} | ||
|
||
$result = tap($this->user()->forceFill([ | ||
$attribute => Hash::make($password), | ||
]))->save(); | ||
$result = $this->rehashUserPassword($password, $attribute); | ||
|
||
if ($this->recaller() || | ||
$this->getCookieJar()->hasQueued($this->getRecallerName())) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello - Just to point out that this will never work if the Authenticable object returned by $this->user() does not use attribute to retrieve the password .
Ideally we should use
getAuthPassword
insteadFor example in my application my Authenticable is not an Eloquent model at all.
(i did have to create a forceFill function in order for this function to work though)