Files
UAS_WEBGIS_MuhammadFarras_D…/WebGIS_PovertyMap/generate_hash.php
T
2026-06-09 20:22:09 +07:00

96 lines
3.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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 (password seragam: "password")
$demoUsers = [
['username' => 'admin', 'nama' => 'Administrator Sistem', 'role' => 'admin', 'password' => 'password'],
['username' => 'petugas', 'nama' => 'Petugas Lapangan', 'role' => 'petugas', 'password' => 'password'],
['username' => 'pengurus', 'nama' => 'Pengurus Rumah Ibadah', 'role' => 'pengurus', 'password' => 'password'],
['username' => 'walikota', 'nama' => 'Walikota Pontianak', 'role' => 'walikota', 'password' => 'password'],
];
$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>password</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>