First commit
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
// ============================================================
|
||||
// generate_hash.php – Generate bcrypt hash & insert akun demo
|
||||
// Akses sekali: http://localhost/WebGIS/pertemuan fix/generate_hash.php
|
||||
// HAPUS file ini setelah digunakan!
|
||||
// ============================================================
|
||||
|
||||
require_once 'config.php';
|
||||
|
||||
// Daftar akun demo yang akan di-insert / update
|
||||
$demoUsers = [
|
||||
['username' => 'admin', 'nama' => 'Administrator Sistem', 'role' => 'admin', 'password' => 'admin123'],
|
||||
['username' => 'pengurus', 'nama' => 'Pengurus Rumah Ibadah', 'role' => 'pengurus', 'password' => 'pengurus123'],
|
||||
['username' => 'walikota', 'nama' => 'Walikota Pontianak', 'role' => 'walikota', 'password' => 'walikota123'],
|
||||
];
|
||||
|
||||
$db = getDB();
|
||||
$results = [];
|
||||
|
||||
foreach ($demoUsers as $u) {
|
||||
$hash = password_hash($u['password'], PASSWORD_DEFAULT);
|
||||
|
||||
// INSERT or UPDATE
|
||||
$stmt = $db->prepare(
|
||||
"INSERT INTO users (username, nama_lengkap, role, password_hash)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
nama_lengkap = VALUES(nama_lengkap),
|
||||
role = VALUES(role),
|
||||
password_hash = VALUES(password_hash)"
|
||||
);
|
||||
$stmt->bind_param('ssss', $u['username'], $u['nama'], $u['role'], $hash);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$results[] = [
|
||||
'status' => '✅ OK',
|
||||
'username' => $u['username'],
|
||||
'role' => $u['role'],
|
||||
'hash' => $hash
|
||||
];
|
||||
} else {
|
||||
$results[] = [
|
||||
'status' => '❌ ERROR: ' . $stmt->error,
|
||||
'username' => $u['username'],
|
||||
'role' => $u['role'],
|
||||
'hash' => '-'
|
||||
];
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
// Output sebagai HTML yang mudah dibaca
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Generate Hash – WebGIS</title>
|
||||
<style>
|
||||
body { font-family: monospace; background:#111; color:#e2e8f0; padding:30px; }
|
||||
h2 { color:#60a5fa; margin-bottom:20px; }
|
||||
table { border-collapse:collapse; width:100%; }
|
||||
th,td { border:1px solid #334155; padding:10px 14px; text-align:left; font-size:13px; }
|
||||
th { background:#1e293b; color:#94a3b8; font-weight:700; }
|
||||
.ok { color:#4ade80; }
|
||||
.err { color:#f87171; }
|
||||
.warn { background:#1c1917; border:1px solid #f59e0b; color:#fbbf24; padding:16px; border-radius:8px; margin-top:24px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>🔑 Generate Hash – Akun Demo WebGIS</h2>
|
||||
<table>
|
||||
<tr><th>Status</th><th>Username</th><th>Role</th><th>Password</th><th>Hash (bcrypt)</th></tr>
|
||||
<?php foreach($results as $r): ?>
|
||||
<tr>
|
||||
<td class="<?= str_starts_with($r['status'],'✅') ? 'ok':'err' ?>"><?= $r['status'] ?></td>
|
||||
<td><?= htmlspecialchars($r['username']) ?></td>
|
||||
<td><?= htmlspecialchars($r['role']) ?></td>
|
||||
<td><?= ($r['username'].'123') ?></td>
|
||||
<td style="font-size:11px;word-break:break-all"><?= htmlspecialchars($r['hash']) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
<div class="warn">
|
||||
⚠️ <strong>PERHATIAN:</strong> File ini sudah tidak diperlukan. Hapus <code>generate_hash.php</code> setelah proses selesai untuk keamanan sistem.
|
||||
</div>
|
||||
<p style="margin-top:20px;color:#64748b">
|
||||
Setelah berhasil, buka <a href="login.html" style="color:#60a5fa">login.html</a> dan coba login.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user