servnest/public/auth/login.php

54 lines
1.5 KiB
PHP
Raw Normal View History

2022-04-23 01:57:43 +02:00
<?php require "../../common/top.php"; ?>
2021-01-22 21:58:46 +01:00
2021-02-17 22:48:49 +01:00
<form method="post">
2022-04-18 16:05:00 +02:00
<label for="username">Identifiant</label><br>
<input required="" minlength="4" maxlength="32" pattern="<?= USERNAME_REGEX ?>" id="username" name="username" type="text" placeholder="lain">
<br>
2021-01-22 21:58:46 +01:00
2022-04-18 16:05:00 +02:00
<label for="password">Clé de passe</label><br>
<input required="" autocomplete="current-password" minlength="8" maxlength="1024" pattern="<?= PASSWORD_REGEX ?>" id="password" name="password" type="password" placeholder="************************">
<br>
2021-01-22 21:58:46 +01:00
2022-04-18 16:05:00 +02:00
<input type="submit">
2021-02-17 22:48:49 +01:00
</form>
2021-01-22 21:58:46 +01:00
2021-02-17 22:48:49 +01:00
Pas de compte ? <a class="authButton" href="register">En créer un</a>
2021-01-25 13:39:31 +01:00
2021-02-17 22:48:49 +01:00
<?php
2021-01-22 21:58:46 +01:00
2021-02-17 22:48:49 +01:00
if (isset($_POST['username']) AND isset($_POST['password'])) {
2021-01-22 21:58:46 +01:00
2022-04-18 16:05:00 +02:00
antiCSRF();
2021-08-05 14:04:33 +02:00
2022-04-18 16:05:00 +02:00
if (!checkPasswordFormat($_POST['password']))
exit("Le format du mot de passe n'est pas valide !");
2021-01-22 21:58:46 +01:00
2022-04-18 16:05:00 +02:00
if (!checkUsernameFormat($_POST['username']))
exit("Le format du nom du compte n'est pas valide !");
2021-01-22 21:58:46 +01:00
2022-04-18 16:05:00 +02:00
if (checkPassword($_POST['username'], $_POST['password'])) {
2022-04-18 16:05:00 +02:00
$_SESSION['username'] = htmlspecialchars($_POST['username']);
2022-04-18 16:05:00 +02:00
if (outdatedPasswordHash($_SESSION['username']))
changePassword($_SESSION['username'], $_POST['password']);
2022-04-18 16:05:00 +02:00
if (isset($_GET['redir'])) {
if (preg_match("/^[0-9a-z\/-]+$/", $_GET['redir']))
2022-04-23 01:57:43 +02:00
header("Location: " . PREFIX . "/" . $_GET['redir']);
2022-04-18 16:05:00 +02:00
else
exit("ERROR : Wrong character in redir argument");
} else {
2022-04-23 01:57:43 +02:00
header("Location: " . PREFIX . "/");
2022-04-18 16:05:00 +02:00
}
exit;
} else {
echo "<br>Connexion impossible : mot de passe invalide";
}
2021-02-17 22:48:49 +01:00
}
2021-01-22 21:58:46 +01:00
2021-02-17 22:48:49 +01:00
?>
2021-01-22 21:58:46 +01:00
2022-04-23 01:57:43 +02:00
<?php require "../../common/bottom.php"; ?>