Skip to content

Commit

Permalink
Add missing rehash method
Browse files Browse the repository at this point in the history
  • Loading branch information
akalongman committed May 14, 2024
1 parent 7be70ef commit f1231d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Lodash/Auth/Contracts/AuthServiceContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public function retrieveUserByToken(int $identifier, string $token): ?UserContra

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

public function rehashPasswordIfRequired(UserContract $user, array $credentials, bool $force = false): void;

public function canUserEmulateOtherUser(UserContract $emulatorUser, UserContract $emulatedUser): bool;

public function getGoogleUserByAccessToken(string $googleToken): ?UserContract;
Expand Down
15 changes: 10 additions & 5 deletions src/Lodash/Auth/InternalUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,35 @@ public function __construct(AuthServiceContract $authService, array $config)
$this->config = $config;
}

public function retrieveById($identifier)
public function retrieveById($identifier): ?Authenticatable
{
return $this->authService->retrieveUserById((int) $identifier);
}

public function retrieveByToken($identifier, $token)
public function retrieveByToken($identifier, $token): ?Authenticatable
{
return $this->authService->retrieveUserByToken((int) $identifier, $token);
}

public function updateRememberToken(Authenticatable $user, $token)
public function updateRememberToken(Authenticatable $user, $token): void
{
$this->authService->updateRememberToken($user, $token);
}

public function retrieveByCredentials(array $credentials)
public function retrieveByCredentials(array $credentials): ?Authenticatable
{
return $this->authService->retrieveByCredentials($credentials);
}

public function validateCredentials(Authenticatable $user, array $credentials)
public function validateCredentials(Authenticatable $user, array $credentials): bool
{
$plain = $credentials['password'];

return $this->authService->validateCredentials($user, $plain);
}

public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false): void
{
$this->authService->rehashPasswordIfRequired($user, $credentials, $force);
}
}
11 changes: 11 additions & 0 deletions src/Lodash/Auth/Services/AuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ public function validateCredentials(UserContract $user, string $password): bool
return $this->hasher->check($password, $user->getAuthPassword());
}

public function rehashPasswordIfRequired(UserContract $user, array $credentials, bool $force = false): void
{
if (! $this->hasher->needsRehash($user->getAuthPassword()) && ! $force) {
return;
}

$user->forceFill([
$user->getAuthPasswordName() => $this->hasher->make($credentials['password']),
])->save();
}

public function canUserEmulateOtherUser(UserContract $emulatorUser, UserContract $emulatedUser): bool
{
// Should be override in subclass
Expand Down

0 comments on commit f1231d9

Please sign in to comment.