34000-vm/db/seed.php
Flatlogic Bot 8d45670c2f Ver 1
2025-09-10 20:32:30 +00:00

30 lines
958 B
PHP

<?php
require_once __DIR__ . '/config.php';
try {
$pdo = db();
// Add a default admin user if one doesn't exist
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = 'admin'");
$stmt->execute();
if ($stmt->fetch()) {
echo "Admin user already exists.\n";
} else {
$username = 'admin';
$password = 'password'; // You should change this!
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$role = 'super_admin';
$stmt = $pdo->prepare("INSERT INTO users (username, password, role) VALUES (:username, :password, :role)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $hashed_password);
$stmt->bindParam(':role', $role);
$stmt->execute();
echo "Default admin user created with username 'admin' and password 'password'.\n";
}
} catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage());
}