This commit is contained in:
2025-12-12 20:19:29 +09:00
parent 47cf4f9f54
commit e648d83d08

View File

@@ -178,12 +178,11 @@ function assert_unless_success(Result $assertion, Throwable|string|null $descrip
return false;
}
if (AUTH_ENABLED) {
function getcookie(string $name): string|null {
function getcookie(string $name): string|null {
return $_COOKIE[$name] ?? null;
}
}
function namecolor(\stdClass $userData): string {
function namecolor(\stdClass $userData): string {
$ban = "#888888";
$male = "#97ACEF";
$female = "#F185C9";
@@ -200,9 +199,9 @@ if (AUTH_ENABLED) {
$suffix = $userData->gender === 0 ? 'くん' : ($userData->gender === 1 ? 'ちゃん' : 'さん');
return $color.$suffix;
}
}
function make_csrf_token(?bool $force = false): string {
function make_csrf_token(?bool $force = false): string {
if (null !== getcookie('csrf_token') && !$force) return getcookie('csrf_token');
$token = bin2hex(random_bytes(32));
setcookie('csrf_token', $token, [
@@ -214,11 +213,10 @@ if (AUTH_ENABLED) {
'samesite' => 'Strict'
]);
return $token;
}
}
function verify_csrf_token(string $token): bool {
function verify_csrf_token(string $token): bool {
return null !== getcookie('csrf_token') && hash_equals(getcookie('csrf_token'), $token);
}
}
function count_special_chars(string $str): int {