mirror of
https://github.com/ellite/Wallos.git
synced 2025-12-23 23:18:07 -05:00
18 lines
511 B
PHP
18 lines
511 B
PHP
<?php
|
|
|
|
if (session_status() !== PHP_SESSION_ACTIVE) {
|
|
session_start();
|
|
}
|
|
|
|
function generate_csrf_token(): string {
|
|
if (empty($_SESSION['csrf_token'])) {
|
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
}
|
|
return $_SESSION['csrf_token'];
|
|
}
|
|
|
|
function verify_csrf_token(?string $token): bool {
|
|
if (empty($_SESSION['csrf_token']) || empty($token)) return false;
|
|
// Use hash_equals to avoid timing attacks
|
|
return hash_equals($_SESSION['csrf_token'], $token);
|
|
} |