-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
100 lines (90 loc) · 4.06 KB
/
index.php
File metadata and controls
100 lines (90 loc) · 4.06 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
require 'db.php';
$error = "";
$success = "";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$u = trim($_POST['username'] ?? '');
$p = trim($_POST['password'] ?? '');
if (!empty($u) && !empty($p)) {
// 1. Check if user already exists
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$u]);
$user = $stmt->fetch();
if ($user) {
// --- SCENARIO A: EXISTING USER (LOGIN) ---
if (password_verify($p, $user['password'])) {
// Password Matches -> LOG THEM IN
$js_token = htmlspecialchars($u);
echo "<script>
localStorage.setItem('aegis_auth', 'true');
localStorage.setItem('aegis_user', '$js_token');
window.location.href = 'app.php';
</script>";
exit;
} else {
// Password Wrong -> ERROR
$error = "Incorrect password for '$u'.";
}
} else {
// --- SCENARIO B: NEW USER (REGISTER) ---
// Create the account automatically
$hash = password_hash($p, PASSWORD_DEFAULT);
$stmt = $conn->prepare("INSERT INTO users (username, password, role) VALUES (?, ?, 'user')");
if ($stmt->execute([$u, $hash])) {
// Registration Success -> LOG THEM IN IMMEDIATELY
$js_token = htmlspecialchars($u);
echo "<script>
localStorage.setItem('aegis_auth', 'true');
localStorage.setItem('aegis_user', '$js_token');
window.location.href = 'app.php';
</script>";
exit;
} else {
$error = "Database error. Try a different name.";
}
}
} else {
$error = "Username and Password are required.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responder Login</title>
<link rel="icon" type="image/png" href="icon.png">
<link rel="apple-touch-icon" href="icon.png">
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-900 text-white min-h-screen flex items-center justify-center p-6">
<div class="max-w-sm w-full">
<h1 class="text-4xl font-bold mb-2 text-blue-500 text-center">AEGIS</h1>
<p class="text-gray-400 mb-8 text-center text-sm uppercase tracking-widest">Field Access</p>
<?php if($error): ?>
<div class="bg-red-500/20 border border-red-500 text-red-200 p-3 rounded-lg mb-6 text-center text-sm">
<?php echo $error; ?>
</div>
<?php endif; ?>
<div class="bg-gray-800/50 p-6 rounded-2xl border border-gray-700">
<form method="POST" class="space-y-4">
<div>
<label class="block text-gray-500 text-xs font-bold mb-1">USERNAME</label>
<input type="text" name="username" required class="w-full bg-gray-900 border border-gray-600 rounded-lg p-3 focus:border-blue-500 outline-none text-white transition-colors" placeholder="Create or Enter Name">
</div>
<div>
<label class="block text-gray-500 text-xs font-bold mb-1">PASSWORD</label>
<input type="password" name="password" required class="w-full bg-gray-900 border border-gray-600 rounded-lg p-3 focus:border-blue-500 outline-none text-white transition-colors" placeholder="Create or Verify Pass">
</div>
<button class="w-full bg-blue-600 hover:bg-blue-500 font-bold py-4 rounded-xl transition-all mt-2 shadow-lg">
ENTER SYSTEM
</button>
</form>
<p class="mt-4 text-center text-gray-500 text-xs">
New name? We'll create an account.<br>Existing name? Enter your password.
</p>
</div>
</div>
</body>
</html>