The following files exists in this folder. Click to view.
index.php58 lines UTF-8 Unix (LF) 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
<?php
session_start();
require_once "functions/database.php";
function attempt_login($username, $password)
{
global $db;
$result = $db->query("SELECT userId, `password` FROM accountData WHERE username = :username", array("username"=>$username));
if (!$result)
return null;
var_export($result);
$hash = hash("sha256", $password, false);
echo "<br>" . $result["password"] . "<br>";
echo $hash;
if ($result["password"] == $hash)
return $result["userId"];
return null;
}
$login_failed=false;
if(isset($_POST["submit"])){
$userID = attempt_login($_POST["username"], $_POST["password"]);
if ($userID)
$_SESSION["userID"] = $userID;
else
$login_failed = true;
}
if(isset($_SESSION["userID"])){
header("location: account.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inloggning, Olivers bank</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" autocomplete="off">
<h2>Logga in</h2>
<label>Användarnamn</label>
<input type="text" name="username">
<label>Lösenord</label>
<input type="password" name="password">
<button type="submit" name="submit">Logga in</button>
<p class="error"><?php if ($login_failed) echo "Felaktigt användarnamn eller lösenord." ?></p>
</form>
<a href="signup.php">Skapa konto istället</a>
</body>