tlm/helper.php
2025-03-27 10:29:33 -04:00

59 lines
1.1 KiB
PHP

<?php
function strip_name(string $name): string {
if (str_contains($name, "$")) {
return explode("$", $name, 2)[1];
}
return $name;
}
function generate_id(): string {
return hash("sha256", uniqid("", true));
}
function get_pop($val, string $type=""): string {
global $repopulate;
if ($repopulate[$val]) {
if ($type == "date") {
return "value=\"" . date("Y-m-d", $repopulate[$val]) . "\"";
}
return $repopulate[$val];
}
return "";
}
function get_token(string $username, string $password_hash): string {
return $username . "-" . hash("sha256", $password_hash . $username);
}
function validate_token(string $token): bool {
}
function is_logged_in(): false | array {
$token = $_COOKIE["token"];
if (!$token) {
return false;
}
global $db;
$u = explode("-", $token, 2)[0];
$user_object = pg_select(
$db, "users", array(
"username" => $u
)
);
if ($user_object && get_token($user_object[0]["username"], $user_object[0]["password_hash"]) === $token) {
return $user_object[0];
}
return false;
}
?>