feat: core utilities - CSRF, auth, encryption, PHPMailer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Gestoría LP
2026-03-01 23:28:54 +00:00
parent 10bc97e8b9
commit 322fc78f2b
7 changed files with 7299 additions and 0 deletions

18
includes/csrf.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
function csrfToken(): string {
if (session_status() === PHP_SESSION_NONE) session_start();
if (empty($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
return $_SESSION['csrf_token'];
}
function csrfField(): string {
return '<input type="hidden" name="csrf_token" value="' . htmlspecialchars(csrfToken()) . '">';
}
function csrfValidate(): bool {
if (session_status() === PHP_SESSION_NONE) session_start();
$token = $_POST['csrf_token'] ?? '';
return hash_equals($_SESSION['csrf_token'] ?? '', $token);
}