<?php 
include 'database.php';


$message = "";
     if(isset($_POST['formsend'])){
        
        $message = "bien recu";
        extract($_POST);

        $verif = $mysqli->prepare("SELECT mdp, pseudo FROM utilisateur WHERE email = ?");
        $verif->bind_param("s",$email);
        $verif->execute();
        $verif->store_result();

        if($verif->num_rows == 1){
            $verif->bind_result($hash, $pseudo);
            $verif->fetch();
            

            if(password_verify($mdp,$hash)){
           
                $message = "Le mot de passe est correcte, Bienvenue $pseudo !";

                $_SESSION['email'] = $email;
                $_SESSION['pseudo'] = $pseudo;
                header("Location: profil.php");
            exit;

            }else{
               
                $message = "T trompé, mot de passe incorrect";
            }
        }else{
           $message = "Adresse mail introuvable";
        }


     }
?>