File: /home/nmel17aacb/domains/argentaclassic.be/public_html/admin/create-user.php
<?php
declare(strict_types=1);
require_once __DIR__ . '/../inc/db.php';
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$db->set_charset('utf8');
$setupKey = 'Dfiggi!1';
$message = '';
$error = '';
function h(?string $value): string
{
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$key = trim((string) ($_POST['setup_key'] ?? ''));
$email = trim((string) ($_POST['email'] ?? ''));
$name = trim((string) ($_POST['name'] ?? ''));
$password = (string) ($_POST['password'] ?? '');
if (!hash_equals($setupKey, $key)) {
throw new RuntimeException('De beveiligingscode klopt niet.');
}
if ($email === '' || $name === '' || $password === '') {
throw new RuntimeException('Vul alle velden in.');
}
if (strlen($password) < 10) {
throw new RuntimeException('Gebruik een wachtwoord van minstens 10 tekens.');
}
$stmt = $db->prepare('SELECT user_id FROM users WHERE user_email = ? OR user_name = ? LIMIT 1');
$stmt->bind_param('ss', $email, $name);
$stmt->execute();
if ($stmt->get_result()->fetch_assoc()) {
throw new RuntimeException('Er bestaat al een gebruiker met deze e-mail of gebruikersnaam.');
}
$hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = $db->prepare('INSERT INTO users (user_email, user_name, user_password) VALUES (?, ?, ?)');
$stmt->bind_param('sss', $email, $name, $hash);
$stmt->execute();
$message = 'Gebruiker aangemaakt. Verwijder nu dit bestand: admin/create-user.php';
} catch (Throwable $e) {
$error = $e->getMessage();
}
}
?>
<!doctype html>
<html lang="nl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex,nofollow">
<title>Admin gebruiker aanmaken</title>
<link rel="stylesheet" href="assets/admin.css">
</head>
<body class="login-page">
<main class="panel login-card">
<div class="panel-header">
<h1>Gebruiker aanmaken</h1>
</div>
<div class="panel-body">
<?php if ($message): ?>
<div class="message success"><?= h($message) ?></div>
<?php endif; ?>
<?php if ($error): ?>
<div class="message error"><?= h($error) ?></div>
<?php endif; ?>
<form method="post">
<div>
<label for="setup_key">Beveiligingscode</label>
<input id="setup_key" name="setup_key" type="password" required>
<div class="help">Pas eerst de waarde van <code>$setupKey</code> bovenaan dit bestand aan.</div>
</div>
<div style="margin-top: 14px;">
<label for="email">E-mail/login</label>
<input id="email" name="email" type="text" autocomplete="username" required>
</div>
<div style="margin-top: 14px;">
<label for="name">Naam</label>
<input id="name" name="name" type="text" required>
</div>
<div style="margin-top: 14px;">
<label for="password">Wachtwoord</label>
<input id="password" name="password" type="password" autocomplete="new-password" required>
</div>
<div class="actions">
<button class="btn btn-primary" type="submit">Gebruiker aanmaken</button>
<a class="btn btn-secondary" href="index.php">Naar login</a>
</div>
</form>
</div>
</main>
</body>
</html>