Skip to content

Commit f1231d9

Browse files
committed
Add missing rehash method
1 parent 7be70ef commit f1231d9

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/Lodash/Auth/Contracts/AuthServiceContract.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public function retrieveUserByToken(int $identifier, string $token): ?UserContra
3434

3535
public function validateCredentials(UserContract $user, string $password): bool;
3636

37+
public function rehashPasswordIfRequired(UserContract $user, array $credentials, bool $force = false): void;
38+
3739
public function canUserEmulateOtherUser(UserContract $emulatorUser, UserContract $emulatedUser): bool;
3840

3941
public function getGoogleUserByAccessToken(string $googleToken): ?UserContract;

src/Lodash/Auth/InternalUserProvider.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,35 @@ public function __construct(AuthServiceContract $authService, array $config)
1919
$this->config = $config;
2020
}
2121

22-
public function retrieveById($identifier)
22+
public function retrieveById($identifier): ?Authenticatable
2323
{
2424
return $this->authService->retrieveUserById((int) $identifier);
2525
}
2626

27-
public function retrieveByToken($identifier, $token)
27+
public function retrieveByToken($identifier, $token): ?Authenticatable
2828
{
2929
return $this->authService->retrieveUserByToken((int) $identifier, $token);
3030
}
3131

32-
public function updateRememberToken(Authenticatable $user, $token)
32+
public function updateRememberToken(Authenticatable $user, $token): void
3333
{
3434
$this->authService->updateRememberToken($user, $token);
3535
}
3636

37-
public function retrieveByCredentials(array $credentials)
37+
public function retrieveByCredentials(array $credentials): ?Authenticatable
3838
{
3939
return $this->authService->retrieveByCredentials($credentials);
4040
}
4141

42-
public function validateCredentials(Authenticatable $user, array $credentials)
42+
public function validateCredentials(Authenticatable $user, array $credentials): bool
4343
{
4444
$plain = $credentials['password'];
4545

4646
return $this->authService->validateCredentials($user, $plain);
4747
}
48+
49+
public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false): void
50+
{
51+
$this->authService->rehashPasswordIfRequired($user, $credentials, $force);
52+
}
4853
}

src/Lodash/Auth/Services/AuthService.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ public function validateCredentials(UserContract $user, string $password): bool
171171
return $this->hasher->check($password, $user->getAuthPassword());
172172
}
173173

174+
public function rehashPasswordIfRequired(UserContract $user, array $credentials, bool $force = false): void
175+
{
176+
if (! $this->hasher->needsRehash($user->getAuthPassword()) && ! $force) {
177+
return;
178+
}
179+
180+
$user->forceFill([
181+
$user->getAuthPasswordName() => $this->hasher->make($credentials['password']),
182+
])->save();
183+
}
184+
174185
public function canUserEmulateOtherUser(UserContract $emulatorUser, UserContract $emulatedUser): bool
175186
{
176187
// Should be override in subclass

0 commit comments

Comments
 (0)