servnest/public/auth/login.php

48 lines
1.5 KiB
PHP

<?php require "../../common/html.php"; ?>
<form method="post">
<label for="username">Identifiant</label><br>
<input required="" minlength="4" maxlength="32" pattern="<?= USERNAME_REGEX ?>" id="username" name="username" type="text" placeholder="lain">
<br>
<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>
<input type="submit">
</form>
Pas de compte ? <a class="authButton" href="register">En créer un</a>
<?php
if (isset($_POST['username']) AND isset($_POST['password'])) {
checkPasswordFormat($_POST['password']);
checkUsernameFormat($_POST['username']);
if (userExist($_POST['username']) !== true)
userError("Connexion impossible : ce compte n'existe pas.");
if (checkPassword($_POST['username'], $_POST['password']) !== true)
userError("Connexion impossible : clé de passe invalide.");
$_SESSION['username'] = $_POST['username'];
if (outdatedPasswordHash($_SESSION['username']))
changePassword($_SESSION['username'], $_POST['password']);
if (isset($_GET['redir'])) {
if (preg_match("/^[0-9a-z\/-]+$/", $_GET['redir']) !== 1)
userError("Wrong character in <code>redir</code>.");
header("Location: " . CONF['common']['prefix'] . "/" . $_GET['redir']);
} else {
header("Location: " . CONF['common']['prefix'] . "/");
}
}
?>
<?php closeHTML(); ?>