-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_account.php
More file actions
66 lines (60 loc) · 2.34 KB
/
create_account.php
File metadata and controls
66 lines (60 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
$confirmPassword = $_POST['confirm_password'];
if ($password !== $confirmPassword) {
echo "Passwords do not match!";
exit;
}
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);
try {
$db = new SQLite3('admin_users.db');
// Insert the new admin into the database
$stmt = $db->prepare("INSERT INTO admin_users (username, password) VALUES (:username, :password)");
$stmt->bindValue(':username', $username, SQLITE3_TEXT);
$stmt->bindValue(':password', $hashedPassword, SQLITE3_TEXT);
$stmt->execute();
// Start the session and set admin login details
session_start();
$_SESSION['admin'] = [
'logged_in' => true,
'username' => $username
];
// Redirect to the Admin Dashboard
header('Location: dashboard.php');
exit;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Create Admin Account</title>
</head>
<body class="bg-light">
<div class="container py-5">
<h1 class="text-center mb-4">Create Admin Account</h1>
<form method="POST" class="w-50 mx-auto">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" name="username" id="username" class="form-control" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" name="password" id="password" class="form-control" required>
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">Confirm Password</label>
<input type="password" name="confirm_password" id="confirm_password" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary w-100">Create Account</button>
</form>
</div>
</body>
</html>