basic auth

This commit is contained in:
biglyderv 2024-11-26 11:38:28 -05:00
parent 0bd8a0cfc0
commit 73dafb8999
8 changed files with 274 additions and 0 deletions

27
libs/auth.php Normal file
View file

@ -0,0 +1,27 @@
<?php
require("../libs/test_secret.php");
function auth($token) {
if (is_null($token)) return '!guest';
global $db;
$stmt = $db->prepare("SELECT * FROM token WHERE token = ?");
$stmt->execute([$token]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$result) return '!guest';
$username = $result['username'];
$stmt = $db->prepare("SELECT * FROM auth WHERE username = ?");
$stmt->execute([$username]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$result) return '!guest';
return $username;
}
$username = auth($_COOKIE['token']);
?>

16
libs/page.php Normal file
View file

@ -0,0 +1,16 @@
<?php
require("../libs/auth.php");
function page_header() { ?>
<!DOCTYPE html>
<html>
<head>
<title>NewBiglyChat</title>
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
<?php }
function page_footer() { ?>
</body>
</html>
<?php }
?>