18 lines
No EOL
573 B
PHP
18 lines
No EOL
573 B
PHP
<?php
|
|
class Security {
|
|
// Token generieren (z.B. für Formulare)
|
|
public static function csrf() {
|
|
if (empty($_SESSION['csrf_token'])) {
|
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
}
|
|
return $_SESSION['csrf_token'];
|
|
}
|
|
|
|
// Token beim POST-Request prüfen
|
|
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;
|
|
}
|
|
} |