add login system

This commit is contained in:
root 2020-05-17 14:46:28 +00:00
parent 129a11420b
commit a84965fb1d
1 changed files with 12 additions and 3 deletions

View File

@ -2,9 +2,6 @@
session_start(); session_start();
$db = new SQLite3('ask.db'); $db = new SQLite3('ask.db');
//$version = $db->querySingle('SELECT SQLITE_VERSION()');
$users_table = $db->query("CREATE TABLE IF NOT EXISTS users( $users_table = $db->query("CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
username TEXT, username TEXT,
@ -17,6 +14,18 @@ $logErrorMsg = "";
$validUser = false; $validUser = false;
if(isset($_SESSION["login"])) $validUser = $_SESSION["login"] === true; if(isset($_SESSION["login"])) $validUser = $_SESSION["login"] === true;
if(isset($_POST["log"])){ 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); $validUser = $_POST["logname"] == "admin" && password_verify($_POST["password"], $hash);
if(!$validUser) $errorMsg = "Invalid username or password."; if(!$validUser) $errorMsg = "Invalid username or password.";
else $_SESSION["login"] = true; else $_SESSION["login"] = true;