17 lines
No EOL
533 B
PHP
17 lines
No EOL
533 B
PHP
<?php
|
|
class Security {
|
|
// CSRF Generation
|
|
public static function csrf() {
|
|
if (empty($_SESSION['csrf_token'])) {
|
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
}
|
|
return $_SESSION['csrf_token'];
|
|
}
|
|
// CSRF Validation
|
|
public static function checkCsrf($token) {
|
|
if (!isset($_SESSION['csrf_token']) || $token !== $_SESSION['csrf_token']) {
|
|
throw new Exception("Sicherheits-Token ungültig. Bitte lade die Seite neu.");
|
|
}
|
|
return true;
|
|
}
|
|
} |