Files
woordjes/register.php
T
2026-06-16 11:23:05 +02:00

117 lines
2.2 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'];
if (
strlen($username) < 3 ||
strlen($password) < 6
) {
$error = 'Ongeldige invoer.';
} else {
$folder = userPath($username);
if (is_dir($folder)) {
$error = 'Gebruiker bestaat al.';
} else {
mkdir($folder, 0775, true);
JsonDB::write(
$folder . '/user.json',
[
'username' => $username,
'password' => password_hash(
$password,
PASSWORD_DEFAULT
),
'created' => date('c')
]
);
mkdir(
$folder . '/languages',
0775,
true
);
mkdir(
$folder . '/progress',
0775,
true
);
header('Location: login.php');
exit;
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Registreren</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#222">
<link rel="manifest" href="/manifest.json">
<link rel="stylesheet" href="/assets/css/style.css">
<link rel="apple-touch-icon" sizes="180x180" href="/assets/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/img/favicon.ico">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/img/favicon-16x16.png">
</head>
<body>
<div class="container">
<div class="card">
<h1>Registreren</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">
Account aanmaken
</button>
</form>
<p>
<a href="login.php">Inloggen</a>
</p>
</div>
</div>
</body>
</html>