<?php
require_once 'config.php';

function criarUsuario($username, $password, $exp_date, $is_admin = 0) {
    $db = getConexaoAtiva(); // Pega a conexão interna ou externa automaticamente
    
    // Hash da senha (o Xtream UI costuma usar crypt ou bcrypt dependendo da versão)
    $hashed_password = password_hash($password, PASSWORD_DEFAULT);

    $sql = "INSERT INTO users (username, password, exp_date, admin_enabled, enabled) 
            VALUES (:username, :password, :exp_date, :admin_enabled, 1)";
            
    $stmt = $db->prepare($sql);
    $stmt->bindParam(':username', $username);
    $stmt->bindParam(':password', $hashed_password);
    $stmt->bindParam(':exp_date', $exp_date);
    $stmt->bindParam(':admin_enabled', $is_admin);
    
    if($stmt->execute()) {
        return true;
    }
    return false;
}
?>