28 lines
797 B
PHP
28 lines
797 B
PHP
<?php
|
|
namespace Misuzu;
|
|
|
|
use Index\Security\CSRFP;
|
|
|
|
final class CSRF {
|
|
private static CSRFP $instance;
|
|
|
|
public static function init(string $secretKey, string $identity): void {
|
|
self::$instance = new CSRFP($secretKey, $identity);
|
|
}
|
|
|
|
public static function validate(string $token, int $tolerance = -1): bool {
|
|
return self::$instance->verifyToken($token, $tolerance);
|
|
}
|
|
|
|
public static function token(): string {
|
|
return self::$instance->createToken();
|
|
}
|
|
|
|
public static function validateRequest(int $tolerance = -1): bool {
|
|
$token = (string)filter_input(INPUT_POST, '_csrf');
|
|
if(empty($token))
|
|
$token = (string)filter_input(INPUT_GET, 'csrf');
|
|
|
|
return self::$instance->verifyToken($token, $tolerance);
|
|
}
|
|
}
|