-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-admin-password.php
More file actions
223 lines (191 loc) Β· 7.45 KB
/
fix-admin-password.php
File metadata and controls
223 lines (191 loc) Β· 7.45 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
* Fix Admin Password
* This script resets the admin password to 'admin123'
*
* Access via browser: https://your-domain.com/fix-admin-password.php
*
* β οΈ Delete this file after use!
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fix Admin Password</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
background: white;
border-radius: 12px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
max-width: 600px;
width: 100%;
padding: 40px;
}
h1 { color: #333; margin-bottom: 20px; font-size: 24px; }
.info-box {
background: #f8f9fa;
border-left: 4px solid #667eea;
padding: 15px;
margin: 20px 0;
border-radius: 4px;
}
.success { background: #d4edda; border-left-color: #28a745; color: #155724; }
.error { background: #f8d7da; border-left-color: #dc3545; color: #721c24; }
.warning { background: #fff3cd; border-left-color: #ffc107; color: #856404; }
.log-output {
background: #1e1e1e;
color: #d4d4d4;
padding: 20px;
border-radius: 6px;
font-family: monospace;
font-size: 13px;
line-height: 1.6;
white-space: pre-wrap;
margin: 20px 0;
}
.log-success { color: #4ec9b0; }
.log-error { color: #f48771; }
.log-info { color: #9cdcfe; }
.btn {
background: #667eea;
color: white;
border: none;
padding: 12px 30px;
border-radius: 6px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
text-decoration: none;
display: inline-block;
transition: background 0.3s;
margin-top: 20px;
}
.btn:hover { background: #5568d3; }
.btn-danger { background: #dc3545; }
.btn-danger:hover { background: #c82333; }
</style>
</head>
<body>
<div class="container">
<h1>π§ Fix Admin Password</h1>
<?php if (!isset($_GET['confirm'])): ?>
<div class="info-box warning">
<strong>β οΈ What This Does:</strong><br>
This will reset the admin password to <strong>admin123</strong>
</div>
<p>The test showed that your admin password hash is incorrect. This tool will fix it.</p>
<a href="?confirm=yes" class="btn">Reset Admin Password Now</a>
<?php else: ?>
<div class="log-output"><?php
ob_start();
echo "<span class='log-info'>===================================</span>\n";
echo "<span class='log-info'>Fixing Admin Password</span>\n";
echo "<span class='log-info'>===================================</span>\n\n";
try {
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/includes/Database.php';
require_once __DIR__ . '/includes/Auth.php';
$db = new Database();
$auth = new Auth();
echo "<span class='log-info'>Database connected</span>\n\n";
// Find admin user
$email = ADMIN_EMAIL;
$stmt = $db->prepare("SELECT id, email FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
if (!$user) {
throw new Exception("Admin user not found! Email: " . ADMIN_EMAIL);
}
echo "<span class='log-success'>β Found admin user (ID: " . $user['id'] . ")</span>\n";
echo " Email: " . $user['email'] . "\n\n";
// Generate correct hash for 'admin123'
echo "<span class='log-info'>Generating new password hash for 'admin123'...</span>\n";
$newPassword = 'admin123';
$newHash = $auth->hashPassword($newPassword);
echo "<span class='log-success'>β New hash generated</span>\n";
echo " Hash: " . substr($newHash, 0, 30) . "...\n\n";
// Verify the new hash works
if (!$auth->verifyPassword($newPassword, $newHash)) {
throw new Exception("Hash verification failed! This shouldn't happen.");
}
echo "<span class='log-success'>β Hash verified successfully</span>\n\n";
// Update the password in database
echo "<span class='log-info'>Updating password in database...</span>\n";
$updateStmt = $db->prepare("UPDATE users SET password = ? WHERE id = ?");
$updateStmt->bind_param("si", $newHash, $user['id']);
if (!$updateStmt->execute()) {
throw new Exception("Failed to update password: " . $db->error);
}
echo "<span class='log-success'>β Password updated successfully!</span>\n\n";
// Verify the fix by reading back
echo "<span class='log-info'>Verifying the fix...</span>\n";
$verifyStmt = $db->prepare("SELECT password FROM users WHERE id = ?");
$verifyStmt->bind_param("i", $user['id']);
$verifyStmt->execute();
$verifyResult = $verifyStmt->get_result();
$verifyUser = $verifyResult->fetch_assoc();
if ($auth->verifyPassword($newPassword, $verifyUser['password'])) {
echo "<span class='log-success'>β Verification successful!</span>\n";
echo "<span class='log-success'>β Password is now: admin123</span>\n\n";
} else {
throw new Exception("Verification failed! Password still doesn't work.");
}
echo "<span class='log-info'>===================================</span>\n";
echo "<span class='log-success'>π Password Fixed Successfully!</span>\n";
echo "<span class='log-info'>===================================</span>\n\n";
echo "<span class='log-info'>You can now log in with:</span>\n";
echo " Email: <span class='log-success'>" . ADMIN_EMAIL . "</span>\n";
echo " Password: <span class='log-success'>admin123</span>\n\n";
echo "<span class='log-error'>β οΈ IMPORTANT: Delete this file after use!</span>\n";
$success = true;
} catch (Exception $e) {
echo "\n<span class='log-error'>β Error: " . htmlspecialchars($e->getMessage()) . "</span>\n";
$success = false;
}
$output = ob_get_clean();
echo $output;
?></div>
<?php if (isset($success) && $success): ?>
<div class="info-box success">
<strong>β Password Fixed!</strong><br>
You can now log in with the credentials shown above.
</div>
<a href="/frontend/public/login.html" class="btn">Go to Login Page</a>
<div style="margin-top: 10px;">
<a href="?confirm=yes&delete=yes" class="btn btn-danger"
onclick="return confirm('Delete this file for security?')">
Delete fix-admin-password.php
</a>
</div>
<?php else: ?>
<div class="info-box error">
<strong>Failed to fix password</strong><br>
Check the error message above.
</div>
<?php endif; ?>
<?php endif; ?>
</div>
</body>
</html>
<?php
// Self-delete if requested
if (isset($_GET['delete']) && $_GET['delete'] === 'yes') {
if (unlink(__FILE__)) {
echo '<script>alert("File deleted!"); window.location.href="/frontend/public/login.html";</script>';
}
}
?>