Initial Kaffeekasse SaaS restart

This commit is contained in:
2026-06-15 17:13:38 +02:00
commit b08eb93547
54 changed files with 4617 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Core;
final class Csrf
{
public function __construct(private readonly Session $session)
{
}
public function token(): string
{
$token = $this->session->get('_csrf_token');
if (!is_string($token) || $token === '') {
$token = bin2hex(random_bytes(32));
$this->session->put('_csrf_token', $token);
}
return $token;
}
public function validate(?string $token): bool
{
$expected = $this->session->get('_csrf_token');
return is_string($expected) && is_string($token) && hash_equals($expected, $token);
}
}