Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/Illuminate/Auth/Passwords/CacheTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function __construct(
protected string $hashKey,
protected int $expires = 3600,
protected int $throttle = 60,
protected string $prefix = '',
) {
}

Expand All @@ -41,7 +40,7 @@ public function create(CanResetPasswordContract $user)
$token = hash_hmac('sha256', Str::random(40), $this->hashKey);

$this->cache->put(
$this->prefix.$user->getEmailForPasswordReset(),
$this->cacheKey($user),
[$this->hasher->make($token), Carbon::now()->format($this->format)],
$this->expires,
);
Expand All @@ -58,7 +57,7 @@ public function create(CanResetPasswordContract $user)
*/
public function exists(CanResetPasswordContract $user, #[\SensitiveParameter] $token)
{
[$record, $createdAt] = $this->cache->get($this->prefix.$user->getEmailForPasswordReset());
[$record, $createdAt] = $this->cache->get($this->cacheKey($user));

return $record
&& ! $this->tokenExpired($createdAt)
Expand All @@ -84,7 +83,7 @@ protected function tokenExpired($createdAt)
*/
public function recentlyCreatedToken(CanResetPasswordContract $user)
{
[$record, $createdAt] = $this->cache->get($this->prefix.$user->getEmailForPasswordReset());
[$record, $createdAt] = $this->cache->get($this->cacheKey($user));

return $record && $this->tokenRecentlyCreated($createdAt);
}
Expand Down Expand Up @@ -114,7 +113,7 @@ protected function tokenRecentlyCreated($createdAt)
*/
public function delete(CanResetPasswordContract $user)
{
$this->cache->forget($this->prefix.$user->getEmailForPasswordReset());
$this->cache->forget($this->cacheKey($user));
}

/**
Expand All @@ -125,4 +124,15 @@ public function delete(CanResetPasswordContract $user)
public function deleteExpired()
{
}

/**
* Determine the cache key for the given user.
*
* @param \Illuminate\Contracts\Auth\CanResetPassword $user
* @return string
*/
public function cacheKey(CanResetPasswordContract $user): string
{
return hash('sha256', $user->getEmailForPasswordReset());
}
}
1 change: 0 additions & 1 deletion src/Illuminate/Auth/Passwords/PasswordBrokerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ protected function createTokenRepository(array $config)
$key,
($config['expire'] ?? 60) * 60,
$config['throttle'] ?? 0,
$config['prefix'] ?? '',
);
}

Expand Down
Loading