From a84965fb1d01de4c3df9ff22117f747e6a8fdd5a Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 May 2020 14:46:28 +0000 Subject: [PATCH] add login system --- login.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/login.php b/login.php index 5d831d0..fb9024c 100644 --- a/login.php +++ b/login.php @@ -2,9 +2,6 @@ session_start(); $db = new SQLite3('ask.db'); -//$version = $db->querySingle('SELECT SQLITE_VERSION()'); - - $users_table = $db->query("CREATE TABLE IF NOT EXISTS users( id INTEGER PRIMARY KEY, username TEXT, @@ -17,6 +14,18 @@ $logErrorMsg = ""; $validUser = false; if(isset($_SESSION["login"])) $validUser = $_SESSION["login"] === true; if(isset($_POST["log"])){ + if($_POST["logname"]){ + $user = $_POST["logname"]; + $shadow = $db->querySingle("SELECT shadow FROM users WHERE username = '$user'"); + if(password_verify($_POST["password"],$shadow)){ + echo("Logged in"); + } + else{ + $logErrorMsg = "Incorrect user or password"; + } + } + else $logErrorMsg = "Please input a username"; + $validUser = $_POST["logname"] == "admin" && password_verify($_POST["password"], $hash); if(!$validUser) $errorMsg = "Invalid username or password."; else $_SESSION["login"] = true;