Show sourcecode
The following files exists in this folder. Click to view.
account.php
create_quiz.js
create_quiz.php
fetch_table.php
frontpage.php
header.php
login.php
quiz.php
quiz_answer_finished.php
quiz_creation_finished.php
signup.php
style.css
login.php
81 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
<?php
session_start();
include('../../incl/dbconnection.php');
/**
* @var PDO $dbconn
*/
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inloggning</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="center-container" style="height: 95vh;">
<div>
<form action="" method="post">
<?php
// Försök logga in
try {
$username = isset($_POST['username']) ? $_POST['username'] : null;
$password = isset($_POST['password']) ? $_POST['password'] : null;
if ($username && $password) {
$sqlSelect = "SELECT * FROM quiz_users WHERE username=?";
$selectStmt = $dbconn->prepare($sqlSelect);
$selectStmt->execute([$username]);
$result = $selectStmt->fetch(PDO::FETCH_ASSOC);
if ($result && password_verify($password, $result['password'])) {
echo "<p class='text-center'>Inloggning lyckades! Skickar vidare dig...</p>";
$_SESSION['isLoggedIn'] = true;
$_SESSION['userId'] = $result['user_id'];
$_SESSION['isAdmin'] = $result['is_admin'];
$pageToSendTo = isset($_SESSION['lastVisited']) ? $_SESSION['lastVisited'] : "frontpage.php";
header("Location:$pageToSendTo");
} else {
echo "<p class='text-center'>Inloggning misslyckades: Användarnamn eller lösenord hittades inte</p>";
}
}
} catch (PDOException $e) {
echo "<br>" . $e->getMessage();
}
// Kolla om vi blivit redirectade hit
$redirect = isset($_GET["redirect"]) ? $_GET["redirect"] : "";
if ($redirect == true) {
?>
<h1 class="text-center">För att fortsätta måste du logga in!</h1>
<hr style="width: 100%;">
<?php
}
?>
<h2>Logga in</h2>
<div class="row">
<label for="username">Användarnamn:</label>
<input type="text" name="username" id="username" autocomplete="off" required>
</div>
<div class="row">
<label for="password">Lösenord:</label>
<input type="password" name="password" id="password" autocomplete="off" required>
</div>
<div class="row">
<input type="submit" value="Logga in">
</div>
<div class="row">
<p style="font-size:small">Inget konto? <a href="signup.php">Skapa ett konto</a></p>
</div>
</form>
</div>
</div>
</body>
</html>