Source: lesson_13_g1_risque.php | Résultat |
<b>Page d'authentification<br/> <table border="0" cellspacing="5" cellpadding="5"> <form action="../commons/show_exercises.php? exercise=lesson_13_g2_risque.php" method="POST"> <tr> <td>Nom d'utilisateur : </td> <td><input type="text" size="10" name="user_name"></td> </tr> <tr> <td>Mot de passe : </td> <td><input type="PASS_WORD" size="10" name="password"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" value="Log In"></td> </tr> </form> </table> </center>
Fichier : lesson_13_g2_risque.php
<?php error_reporting(E_ALL); ini_set("display_errors", 1); $status =authenticate($_POST['user_name'], $_POST['password']); // if user/pass combination is correct if ($status == 1) { // initialisation de la session empty($_SESSION)? session_start():print""; // including the username $_SESSION["session_user_name"] = $_POST['user_name']; // dans la pratique on fera une redirection //header("...."); echo "Mot de passe correct"; exit(); } else // user/pass check failed { //dans la pratique on va rediriger la page echo "Vous n'avez pas fourni un mot de passe vous permettant d'entrer sur le site"; exit(); }
// authenticate username/PASS_WORD against a database // returns: 0 if username and PASS_WORD is incorrect // 1 if username and PASS_WORD are correct function authenticate($myUser, $myPass) { global $mysqli; require_once ("../mysql_connexion/mysql_connexion.php"); //mysql_select_db($db) ; $myPass= crypt($myPass, $myUser); $result = mysqli_query($mysqli,"select * from atelierphp_exe_pass_words WHERE PASS_WORD_USER = '$myUser' AND PASS_WORD_PASS = '$myPass'"); // if row exists -> user/pass combination is correct if (mysqli_num_rows($result) >= 1) { return 1; } // user/pass combination is wrong else { return 0; } }
?>
| Page d'authentification
|