First Commit
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class CaptchaController extends Controller
|
||||
{
|
||||
/**
|
||||
* Generate a new arithmetic captcha.
|
||||
*/
|
||||
public function generate(Request $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$a = random_int(1, 20);
|
||||
$b = random_int(1, 20);
|
||||
$operations = ['+', '-', '*'];
|
||||
$operation = $operations[array_rand($operations)];
|
||||
|
||||
if ($operation === '+') {
|
||||
$answer = $a + $b;
|
||||
} elseif ($operation === '-') {
|
||||
$answer = $a - $b;
|
||||
} else {
|
||||
$answer = $a * $b;
|
||||
}
|
||||
|
||||
$expression = "{$a} {$operation} {$b} = ?";
|
||||
|
||||
Session::put('captcha_answer', (string) $answer);
|
||||
|
||||
return response()->json([
|
||||
'expression' => $expression,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user