Add password change feature.
[Project_webapp.git] / includes / formlogin.php
1 <?php
2 $form_email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL);
3 $form_password = filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING);
4
5 if (!$form_email) {
6 echo "The email is not valid. <br>";
7 redirect("index.php?page=login", 3);
8 } elseif (isset($form_email) && isset($form_password)) {
9 if (chk_account($form_email)) {
10 if (chk_password($form_email, $form_password)) {
11 // authentification okay, setup session
12 session_regenerate_id(true);
13 $_SESSION['email'] = $form_email;
14 $_SESSION['IP_address'] = $_SERVER['REMOTE_ADDR'];
15 // redirect to required page
16 echo "You're successfully authenticated. <br>";
17 redirect("index.php", 3);
18 } else {
19 echo "Your password is incorrect for the account email " . $form_email . ". <br>";
20 echo "<a href=\"javascript:history.go(-1)\">Retour</a>";
21 }
22 } else {
23 echo "You do not have an account for the email " . $form_email . ". <br>";
24 echo "Please register first.";
25 redirect("index.php?page=register", 3);
26 }
27 } else {
28 // didn't authenticate for unknown reason, go back to login form
29 echo "Fail to authenticate for unknown reason. <br>";
30 redirect("index.php?page=login", 3);
31 }
32
33 ?>