summaryrefslogtreecommitdiff
path: root/src/accounts.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-20 10:46:32 +0500
committerilotterytea <iltsu@alright.party>2025-04-20 10:46:32 +0500
commit3b6c6e5774dec41a16da03d1bb8497b448cfa564 (patch)
tree4e9c79624c43c92dbcc288a61f5b92b1772d3c5c /src/accounts.php
parent43e46d21c263fe8a8672e8e4b3ce38803b9cd089 (diff)
feat: users, account management, authentication system
Diffstat (limited to 'src/accounts.php')
-rw-r--r--src/accounts.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/accounts.php b/src/accounts.php
new file mode 100644
index 0000000..4273964
--- /dev/null
+++ b/src/accounts.php
@@ -0,0 +1,29 @@
+<?php
+function authorize_user()
+{
+ session_start();
+
+ if (!isset($_COOKIE["secret_key"])) {
+ if (isset($_SESSION["user_id"])) {
+ session_unset();
+ }
+
+ return;
+ }
+
+ $db = new SQLite3("../../database.db");
+
+ $stmt = $db->prepare("SELECT id, username FROM users WHERE secret_key = :secret_key");
+ $stmt->bindValue("secret_key", $_COOKIE["secret_key"]);
+ $results = $stmt->execute();
+
+ if ($row = $results->fetchArray()) {
+ $_SESSION["user_id"] = $row["id"];
+ $_SESSION["user_name"] = $row["username"];
+ } else {
+ session_regenerate_id();
+ setcookie("secret_key", "", time() - 1000);
+ }
+
+ $db->close();
+} \ No newline at end of file