Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Next Next commit
reset the attempts on lockout to avoid race condition re-lockout
  • Loading branch information
tomschlick committed Apr 23, 2016
commit a2e4271af4a370266c052d44d0b3d6c77aa2a74f
15 changes: 14 additions & 1 deletion src/Illuminate/Cache/RateLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public function tooManyAttempts($key, $maxAttempts, $decayMinutes = 1)

if ($this->attempts($key) > $maxAttempts) {
$this->cache->add($key.':lockout', time() + ($decayMinutes * 60), $decayMinutes);

$this->resetAttempts($key);

return true;
}
Expand Down Expand Up @@ -71,6 +73,17 @@ public function attempts($key)
{
return $this->cache->get($key, 0);
}

/**
* Reset the number of attempts for the given key.
*
* @param string $key
* @return mixed
*/
public function resetAttempts($key)
{
return $this->cache->forget($key;
}

/**
* Get the number of retries left for the given key.
Expand All @@ -94,7 +107,7 @@ public function retriesLeft($key, $maxAttempts)
*/
public function clear($key)
{
$this->cache->forget($key);
$this->resetAttempts($key);

$this->cache->forget($key.':lockout');
}
Expand Down