add login system
This commit is contained in:
parent
129a11420b
commit
a84965fb1d
15
login.php
15
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;
|
||||
|
|
Loading…
Reference in New Issue