Initial commit
This commit is contained in:
17
app/Core/Csrf.php
Normal file
17
app/Core/Csrf.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace App\Core;
|
||||
|
||||
class Csrf {
|
||||
public static function generate() {
|
||||
Session::start();
|
||||
if (empty($_SESSION['csrf_token'])) {
|
||||
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
||||
}
|
||||
return $_SESSION['csrf_token'];
|
||||
}
|
||||
|
||||
public static function verify($token) {
|
||||
Session::start();
|
||||
return hash_equals($_SESSION['csrf_token'] ?? '', $token);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user