simple tokenized loginsystem

This commit is contained in:
Lauren Toivanen 2024-09-28 08:21:52 +03:00
parent 8f2311df0b
commit f5371aba5d
Signed by: jt
GPG key ID: 9151B109B73ECAD5
5 changed files with 124 additions and 10 deletions

16
login.php Normal file
View file

@ -0,0 +1,16 @@
<?php
if (empty($_POST) || !isset($_POST['submit'])) {
die("Login canceled: no post / no submit");
}
require_once('inc/database.php');
$db = new DataBase();
$user = $db->getUserByHandle($_POST['name']);
if ($db->passwordVerify($user['user.id'], $_POST['pass'])) {
$token = $db->tokenAdd($user['user.id']);
$token64 = base64_encode($token);
$expires = time() + 2592000; // 30 days
setcookie('token', $token64, $expires);
}
header("Location: /");
?>