Skip to content

Commit

Permalink
Merge pull request #246 from shahramfdl/master
Browse files Browse the repository at this point in the history
Separating captcha expiration from Laravel session lifetime
  • Loading branch information
mewebstudio authored Sep 22, 2022
2 parents 91ce822 + 69495bb commit 68e3539
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ return [
'height' => 36,
'quality' => 90,
'math' => true, //Enable Math Captcha
'expire' => 60, //Stateless/API captcha expiration
'expire' => 60, //Captcha expiration
],
// ...
];
Expand Down
9 changes: 6 additions & 3 deletions src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ public function create(string $config = 'default', bool $api = false)
$this->image->blur($this->blur);
}

if ($api) {
Cache::put($this->get_cache_key($generator['key']), $generator['value'], $this->expire);
}
Cache::put($this->get_cache_key($generator['key']), $generator['value'], $this->expire);

return $api ? [
'sensitive' => $generator['sensitive'],
Expand Down Expand Up @@ -478,6 +476,11 @@ public function check(string $value): bool
$sensitive = $this->session->get('captcha.sensitive');
$encrypt = $this->session->get('captcha.encrypt');

if (!Cache::pull($this->get_cache_key($key))) {
$this->session->remove('captcha');
return false;
}

if (!$sensitive) {
$value = $this->str->lower($value);
}
Expand Down

0 comments on commit 68e3539

Please sign in to comment.