| Current Path : /home/seto/indexator.pm/src/Core/ |
| Current File : /home/seto/indexator.pm/src/Core/CsrfGuard.php |
<?php
namespace App\Core;
class CsrfGuard
{
public static function getToken(): string
{
if (!Session::has('csrf_token')) {
Session::set('csrf_token', bin2hex(random_bytes(32)));
}
return Session::get('csrf_token');
}
public static function validate(string $token): bool
{
$stored = Session::get('csrf_token', '');
return $stored !== '' && hash_equals($stored, $token);
}
public static function validateRequest(Request $request): bool
{
return self::validate((string) $request->post('_csrf', ''));
}
}