Show sourcecode
The following files exists in this folder. Click to view.
createquiz.php
createtable.php
dbconnection.php
index.php
login.php
myquiz.php
registrera.php
results.php
results2.php
takequiz.php
login.php
54 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log In</title>
</head>
<body>
<form method="post">
<p>Användarnamn: </p>
<input type="text" name="username">
<p>Lösenord: </p>
<input type="password" name="password">
<br>
<br>
<button name="login">
Logga in
</button>
</form>
<br>
<a href="registrera.php">Skapa Konto</a>
<?php
include('dbconnection.php');
if (isset($_POST['login'])) {
$user = $_POST['username'];
$pass = $_POST['password'];
$stmt = $dbconn->prepare(
"SELECT * FROM users WHERE username = :username"
);
$stmt->execute([':username' => $user]);
$row = $stmt->fetch();
if ($row && password_verify($pass ,$row['password'])) {
$_SESSION['user_id'] = $row['id'];
$ustmt = $dbconn->prepare("UPDATE users SET last_login = NOW() WHERE id = :id");
$ustmt->execute([':id' => $row['id']]);
header("Location: index.php");
}
else {
echo "fel inlogg";
}
}
$dbconn = null;
?>
</body>
</html>