coba reset
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
// reset_password.php
|
||||
// Letakkan di root folder: D:\Laragon\www\sinergi\reset_password.php
|
||||
// Akses: http://localhost/sinergi/reset_password.php
|
||||
// HAPUS file ini setelah selesai!
|
||||
|
||||
// ── Auto-detect config ────────────────────────────────────────
|
||||
$configFiles = [
|
||||
__DIR__ . '/config/database.php',
|
||||
__DIR__ . '/config/db.php',
|
||||
__DIR__ . '/config/app.php',
|
||||
__DIR__ . '/app/config/database.php',
|
||||
];
|
||||
foreach ($configFiles as $f) {
|
||||
if (file_exists($f)) require_once $f;
|
||||
}
|
||||
|
||||
// ── Koneksi PDO langsung (tanpa class) ───────────────────────
|
||||
$host = defined('DB_HOST') ? DB_HOST : 'localhost';
|
||||
$dbname = defined('DB_NAME') ? DB_NAME : 'sinergi';
|
||||
$dbuser = defined('DB_USER') ? DB_USER : 'root';
|
||||
$dbpass = defined('DB_PASS') ? DB_PASS : '';
|
||||
$charset = defined('DB_CHARSET') ? DB_CHARSET : 'utf8mb4';
|
||||
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
"mysql:host=$host;dbname=$dbname;charset=$charset",
|
||||
$dbuser, $dbpass,
|
||||
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
|
||||
);
|
||||
} catch (PDOException $e) {
|
||||
die("<b>Koneksi DB gagal:</b> " . $e->getMessage() .
|
||||
"<br>Edit variabel \$host, \$dbname, \$dbuser, \$dbpass di baris 15-18 file ini.");
|
||||
}
|
||||
|
||||
// ── Proses form ───────────────────────────────────────────────
|
||||
$message = '';
|
||||
$newPassword = 'Admin123'; // password default
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = trim($_POST['username'] ?? '');
|
||||
$newPassword = trim($_POST['new_password'] ?? '');
|
||||
|
||||
if ($username && $newPassword) {
|
||||
// Cek user ada
|
||||
$stmt = $pdo->prepare("SELECT id, username, password FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($user) {
|
||||
// Verifikasi apakah password lama cocok (info saja)
|
||||
$testPasswords = ['password', 'admin', 'superadmin', '123456', 'Admin123', 'Password123', $newPassword];
|
||||
$found = null;
|
||||
foreach ($testPasswords as $p) {
|
||||
if (password_verify($p, $user['password'])) {
|
||||
$found = $p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset password
|
||||
$hash = password_hash($newPassword, PASSWORD_BCRYPT, ['cost' => 12]);
|
||||
$pdo->prepare("UPDATE users SET password = ? WHERE username = ?")
|
||||
->execute([$hash, $username]);
|
||||
|
||||
$message = "
|
||||
<div style='color:green;border:1px solid green;padding:10px;margin:10px 0'>
|
||||
✅ Password berhasil direset!<br>
|
||||
Username: <b>$username</b><br>
|
||||
Password baru: <b>$newPassword</b><br>
|
||||
" . ($found ? "Password lama yang cocok: <b>$found</b>" : "Password lama tidak cocok dengan daftar test (mungkin custom)") . "
|
||||
</div>
|
||||
";
|
||||
} else {
|
||||
$message = "<div style='color:red;border:1px solid red;padding:10px;margin:10px 0'>❌ Username '$username' tidak ditemukan.</div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Tampilkan semua user ───────────────────────────────────────
|
||||
$users = $pdo->query("SELECT id, username, email, is_active, LEFT(password,30) as pass_preview FROM users ORDER BY id")->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>SINERGI - Reset Password</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; max-width: 700px; margin: 40px auto; padding: 20px; }
|
||||
table { width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 13px; }
|
||||
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
|
||||
th { background: #f4f4f4; }
|
||||
input { padding: 8px; margin: 4px 0; width: 100%; box-sizing: border-box; }
|
||||
button { padding: 10px 20px; background: #d9534f; color: white; border: none; cursor: pointer; border-radius: 4px; }
|
||||
.warning { background: #fff3cd; border: 1px solid #ffc107; padding: 10px; border-radius: 4px; margin-bottom: 20px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>🔑 SINERGI — Reset Password</h2>
|
||||
<div class="warning">⚠️ <b>HAPUS file ini setelah selesai!</b> Jangan biarkan file ini ada di server production.</div>
|
||||
|
||||
<?= $message ?>
|
||||
|
||||
<h3>Daftar Users</h3>
|
||||
<table>
|
||||
<tr><th>ID</th><th>Username</th><th>Email</th><th>Aktif</th><th>Password Hash (30 char)</th></tr>
|
||||
<?php foreach ($users as $u): ?>
|
||||
<tr>
|
||||
<td><?= $u['id'] ?></td>
|
||||
<td><?= htmlspecialchars($u['username']) ?></td>
|
||||
<td><?= htmlspecialchars($u['email']) ?></td>
|
||||
<td><?= $u['is_active'] ? '✅' : '❌' ?></td>
|
||||
<td style="font-size:11px;font-family:monospace"><?= htmlspecialchars($u['pass_preview']) ?>...</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<h3>Reset Password</h3>
|
||||
<form method="POST">
|
||||
<label>Username:</label>
|
||||
<input type="text" name="username" value="superadmin" required>
|
||||
<label>Password Baru:</label>
|
||||
<input type="text" name="new_password" value="Admin123" required>
|
||||
<br><br>
|
||||
<button type="submit">🔄 Reset Password</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user