servnest/public/auth/password.php

48 lines
1.4 KiB
PHP
Raw Normal View History

2022-04-23 01:57:43 +02:00
<?php require "../../common/top.php"; ?>
2021-02-17 22:48:49 +01:00
<p>
2022-04-18 16:05:00 +02:00
Vous pouvez ici changer le mot de passe permettant d'accéder à votre compte Niver.
2021-02-17 22:48:49 +01:00
</p>
2021-02-17 22:48:49 +01:00
<form method="post">
2022-04-18 16:05:00 +02:00
<label for="currentPassword">Mot de passe actuel</label><br>
<input required="" autocomplete="current-password" minlength="8" maxlength="1024" pattern="<?= PASSWORD_REGEX ?>" id="currentPassword" name="currentPassword" type="password" placeholder="************"><br>
2022-04-18 16:05:00 +02:00
<label for="newPassword">Nouveau mot de passe</label><br>
<input required="" autocomplete="new-password" minlength="8" maxlength="1024" pattern="<?= PASSWORD_REGEX ?>" id="newPassword" name="newPassword" type="password" placeholder="************"><br>
2022-04-18 16:05:00 +02:00
<input type="submit">
2021-02-17 22:48:49 +01:00
</form>
2021-02-17 22:48:49 +01:00
<?php
2021-02-17 22:48:49 +01:00
if (isset($_SESSION['username']) AND isset($_POST['newPassword']) AND isset($_POST['currentPassword'])) {
2022-04-18 16:05:00 +02:00
antiCSRF();
2021-08-05 14:04:33 +02:00
checkPasswordFormat($_POST['newPassword']);
if (checkPassword($_SESSION['username'], $_POST['currentPassword'])) {
2022-04-18 16:05:00 +02:00
$username = $_SESSION['username'];
$newPassword = password_hash($_POST['newPassword'], PASSWORD_DEFAULT);
2022-04-18 16:05:00 +02:00
$db = new PDO('sqlite:' . DB_PATH);
2022-04-18 16:05:00 +02:00
$stmt = $db->prepare("UPDATE users SET password = :password WHERE username = :username");
2022-04-18 16:05:00 +02:00
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $newPassword);
2022-04-18 16:05:00 +02:00
$stmt->execute();
2022-04-18 16:05:00 +02:00
} else {
echo "<br>Le mot de passe actuel n'est pas bon !";
}
2021-02-17 22:48:49 +01:00
}
2021-02-17 22:48:49 +01:00
?>
2022-04-23 01:57:43 +02:00
<?php require "../../common/bottom.php"; ?>