Initial commit
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
ssww23
2026-03-10 00:55:37 +03:00
parent fc0f28d830
commit 93a655235a
155 changed files with 24768 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Http\Controllers\Concerns;
use Illuminate\Http\Request;
trait ManagesCaptcha
{
protected function buildCaptchaQuestion(Request $request, string $context): string
{
$first = random_int(2, 9);
$second = random_int(1, 9);
$isSubtraction = random_int(0, 1) === 1;
if ($isSubtraction && $second > $first) {
[$first, $second] = [$second, $first];
}
$question = $isSubtraction ? "{$first} - {$second}" : "{$first} + {$second}";
$answer = (string) ($isSubtraction ? $first - $second : $first + $second);
$request->session()->put("captcha.{$context}.answer", $answer);
return $question;
}
protected function captchaIsValid(Request $request, string $context, string $field = 'captcha'): bool
{
$expected = (string) $request->session()->get("captcha.{$context}.answer", '');
$provided = trim((string) $request->input($field, ''));
return $expected !== '' && hash_equals($expected, $provided);
}
protected function clearCaptcha(Request $request, string $context): void
{
$request->session()->forget("captcha.{$context}.answer");
}
}