Update php/connexion.php

This commit is contained in:
Alexis HADJEM--BRANCHER 2024-06-11 11:27:58 +02:00
parent 96b374d16b
commit 835e74c820

View File

@ -1,37 +1,73 @@
<?php <?php
// Informations de connexion à la base de données // Informations de connexion à la base de données
$db = mysqli_connect("dwarves.iut-fbleau.fr","ghouar-t","Bases2023","ghouar-t"); require_once 'common.php';
if(!$db){ session_start();
die("Connexion BD impossible."); if (!empty($_REQUEST['login']) && !empty($_REQUEST['password'])) {
}else{ $db = initDatabase();
echo "Connexion BD reussie ! <br>"; $login = $_POST['login'];
} $password = $_POST['password'];
// Récupération des données du formulaire
$login = $_POST['login'];
$password = $_POST['password'];
$result=mysqli_query($db,"SELECT * FROM user WHERE login = '$login' "); $result=mysqli_query($db,"SELECT * FROM user WHERE login = '$login' ");
if (mysqli_num_rows($result) > 0) { if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result); $row = mysqli_fetch_assoc($result);
$hash = $row['mdp']; $hash = $row['mdp'];
if (password_verify($password, $hash)) { if (password_verify($password, $hash)) {
echo "Connexion réussie au mdp !"; if ($login) {
$_SESSION['login'] = $login;
header('Location: ../index.html');
exit();
}
} else { } else {
echo "Échec de la connexion : couple login/mot de passe invalide."; echo "Échec de la connexion : couple login/mot de passe invalide.";
} }
} else { } else {
echo "Échec de la connexion : login invalide."; echo "Échec de la connexion : login invalide.";
} }
mysqli_close($db);
}
// Récupération des données du formulaire
?> ?>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/style.css">
<title>Page de Connexion</title>
</head>
<body>
<div id="content_cours">
<header>
<nav>
<a href="../index.html">Page d'accueil</a>
</nav>
</header>
<h2>Connexion</h2>
<form action="" method="post">
<label for="login">Login :</label><br>
<input type="text" id="login" name="login" value="<?php if (isset($_REQUEST['login'])) { echo $_REQUEST['login']; } ?>"><br>
<label for="password">Mot de passe :</label><br>
<input type="password" id="password" name="password" value="<?php if (isset($_REQUEST['login'])) { echo $_REQUEST['login']; } ?>"><br>
<input type="submit" value="Se connecter">
</form>
</body>
</html>