<?php
session_start();

if (isset($_POST["valider"])) {
    include("confconnect.php");
    $pseudo = $_POST["pseudo"];
    $password = $_POST["password"];
    $verify = $conn->prepare("SELECT * FROM DashBoard.users WHERE pseudo=? LIMIT 1");
    $verify->execute(array($pseudo));
    $user = $verify->fetch();

    if ($user && $user["password"] === md5($password)) {
        $_SESSION["prenom_nom"] = ucfirst(strtolower($user["prenom"])) . " " . strtoupper($user["nom"]);
        $_SESSION["connecter"] = "yes";
        header("location:index.php");
        exit();
    } else {
        $erreur = "Mauvais login ou mot de passe!";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="stylelogin.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <title>Login</title>
</head>
<body onLoad="document.fo.login.focus()">

    <div class="erreur"><?php echo $erreur ?></div>

<div class="container-fluid">
    <div class="row no-gutter">
        <!-- The image half -->
        <div class="col-md-6 d-none d-md-flex ">
            <img src="img/duck.gif">
        </div>


        <!-- The content half -->
<div class="col-md-6 bg-light">
    <div class="login d-flex align-items-center py-5">

    <div class="container">
                    <div class="row">
                        <div class="col-lg-10 col-xl-7 mx-auto">
                            <h3 class="display-4">Authentification</h3>
                            <form  name="form"  method="post"  action="">
                                <div class="form-group mb-3">
                                    <input type="text" name="pseudo" placeholder="Votre Pseudo" class="form-control rounded-pill border-0 shadow-sm px-4">
                                </div>
                                <div class="form-group mb-3">
                                    <input type="password" name="password" placeholder="Mot de passe" class="form-control rounded-pill border-0 shadow-sm px-4 text-primary">
                                </div>
                                <button type="submit" name="valider" value="S'authentifier" class="btn btn-primary btn-block text-uppercase mb-2 rounded-pill shadow-sm">Sign in</button> 
                                </div>
                            </form>
                        </div>
                    </div>
                </div><!-- End -->

            </div>
        </div><!-- End -->

    </div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
