95 lines
1.3 KiB
PHP
95 lines
1.3 KiB
PHP
<?php
|
|
|
|
require_once 'includes/config.php';
|
|
require_once 'includes/jsondb.php';
|
|
require_once 'includes/functions.php';
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
$username = sanitize($_POST['username']);
|
|
$password = $_POST['password'];
|
|
|
|
$userFile =
|
|
userPath($username) .
|
|
'/user.json';
|
|
|
|
if (!file_exists($userFile)) {
|
|
|
|
$error = 'Onbekende gebruiker';
|
|
|
|
} else {
|
|
|
|
$user = JsonDB::read($userFile);
|
|
|
|
if (
|
|
password_verify(
|
|
$password,
|
|
$user['password']
|
|
)
|
|
) {
|
|
|
|
$_SESSION['user'] =
|
|
$user['username'];
|
|
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
|
|
} else {
|
|
|
|
$error = 'Fout wachtwoord';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Login</title>
|
|
<link rel="stylesheet" href="assets/css/style.css">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
|
|
<div class="card">
|
|
|
|
<h1>Login</h1>
|
|
|
|
<?php if ($error): ?>
|
|
<p><?= $error ?></p>
|
|
<?php endif; ?>
|
|
|
|
<form method="post">
|
|
|
|
<input
|
|
name="username"
|
|
placeholder="Gebruikersnaam"
|
|
required>
|
|
|
|
<input
|
|
type="password"
|
|
name="password"
|
|
placeholder="Wachtwoord"
|
|
required>
|
|
|
|
<button type="submit">
|
|
Inloggen
|
|
</button>
|
|
|
|
</form>
|
|
|
|
<p>
|
|
<a href="register.php">
|
|
Nieuw account
|
|
</a>
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|