addMinutes(10)->getTimestamp()); return [ 'a' => $a, 'b' => $b, 'question' => sprintf('%d + %d = ?', $a, $b), ]; } /** * Validate the submitted CAPTCHA answer against the session value. */ protected function validateMathCaptcha(): bool { $expected = Session::get('captcha_result'); $expiresAt = Session::get('captcha_expires_at'); // Invalidate the challenge after it is consumed. Session::forget(['captcha_result', 'captcha_expires_at']); if ($expected === null || $expiresAt === null) { return false; } if (now()->getTimestamp() > (int) $expiresAt) { return false; } return (int) $this->input('captcha') === (int) $expected; } }