Initial commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// Script ini hanya dijalankan SEKALI untuk membuat tabel users dan akun admin default.
|
||||
// Hapus file ini setelah selesai dijalankan.
|
||||
|
||||
require_once 'db_config.php';
|
||||
|
||||
// 1. Buat tabel users
|
||||
$sql_table = "CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(100) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
nama_lengkap VARCHAR(200) NOT NULL,
|
||||
role ENUM('admin','operator') NOT NULL DEFAULT 'operator',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
if ($conn->query($sql_table)) {
|
||||
echo "<p style='color:green'>✓ Tabel <strong>users</strong> berhasil dibuat.</p>";
|
||||
} else {
|
||||
echo "<p style='color:red'>✗ Gagal membuat tabel users: " . $conn->error . "</p>";
|
||||
}
|
||||
|
||||
// 2. Insert akun admin default (password: admin123)
|
||||
$password_hash = password_hash('admin123', PASSWORD_BCRYPT);
|
||||
|
||||
$stmt = $conn->prepare("INSERT IGNORE INTO users (username, password, nama_lengkap, role) VALUES (?, ?, ?, 'admin')");
|
||||
$username = 'admin';
|
||||
$nama = 'Administrator';
|
||||
$stmt->bind_param('sss', $username, $password_hash, $nama);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($stmt->affected_rows > 0) {
|
||||
echo "<p style='color:green'>✓ Akun admin berhasil dibuat.</p>";
|
||||
} else {
|
||||
echo "<p style='color:orange'>⚠ Akun admin sudah ada (tidak diubah).</p>";
|
||||
}
|
||||
} else {
|
||||
echo "<p style='color:red'>✗ Gagal membuat akun admin: " . $stmt->error . "</p>";
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
|
||||
echo "<hr>";
|
||||
echo "<p><strong>Kredensial Login:</strong></p>";
|
||||
echo "<p>Username: <code>admin</code></p>";
|
||||
echo "<p>Password: <code>admin123</code></p>";
|
||||
echo "<hr>";
|
||||
echo "<p style='color:red'><strong>PENTING:</strong> Hapus file ini setelah setup selesai!</p>";
|
||||
?>
|
||||
Reference in New Issue
Block a user