<!doctype html>
<html lang="en">
<head>
    <?php include 'include/head.php' ?>
    <title>Inscription</title>
</head>
<body>
<?php include 'include/nav.php' ?>
<div class="container py-2">
    <h4>Inscription</h4>
    <?php
if (isset($_POST['ajouter'])) {
    $login = $_POST['login'];
    $pwd = password_hash($_POST['password'], PASSWORD_DEFAULT); // 🔐 Hash sécurisé

    if (!empty($login) && !empty($pwd)) {
        require_once 'include/database.php';
        $date = date('Y-m-d');

        // ✅ Requête corrigée avec colonnes nommées
        $sqlState = $pdo->prepare("INSERT INTO utilisateur (login, password, date_creation) VALUES (?, ?, ?)");
        $sqlState->execute([$login, $pwd, $date]);

        header('location: connexion.php');
    } else {
        echo '<div class="alert alert-danger" role="alert">
                Login , password sont obligatoires
              </div>';
    }
}

    ?>
    <form method="post" autocomplete="off">
        <label class="form-label">Login</label>
        <input type="text" class="form-control" name="login">

        <label class="form-label">Password</label>
        <input type="password" class="form-control" name="password">

        <input type="submit" value="Inscrire" class="btn btn-primary my-2" name="ajouter">
    </form>
</div>

</body>
</html>