-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecovery.php
64 lines (53 loc) · 2.38 KB
/
recovery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require('src/inc/pdo.php');
require('src/inc/functions.php');
session_start();
$errors = [];
if (!empty($_GET['mail']) && !empty($_GET['token']) && filter_var($_GET['mail'], FILTER_VALIDATE_EMAIL)) {
$mail = checkXss($_GET['mail']);
$token = checkXss($_GET['token']);
$user = select($pdo, 'bn_users', '*', 'mail', $mail);
if (!empty($user) && $user['token'] == $token) {
if (!empty($_POST['submit'])) {
$password = checkXss($_POST['password']);
$passwordConfirm = checkXss($_POST['password-confirm']);
$errors = checkField($errors, $password, 'password', 6, 200);
$errors = checkField($errors, $passwordConfirm, 'password-confirm', 6, 200);
if ($password != $passwordConfirm) $errors['password-confirm'] == 'Les mots de passes ne sont pas identiques';
if (count($errors) == 0) {
$passwordHashed = password_hash($password, PASSWORD_BCRYPT);
$token = generateRandomString(200);
update($pdo, 'bn_users', [
'password = "' . $passwordHashed . '"',
'token = "' . $token . '"'
], 'id', $user['id']);
$user = select($pdo, 'bn_users', '*', 'id', $user['id']);
header('Location: ./login.php');
die();
}
}
} else {
header('Location: ./error.php');
die();
}
} else {
header('Location: ./error.php');
die();
}
$title = 'Changement de mot de passe - Bookination';
include('src/template/header.php');
?>
<section id="recovery_password">
<div class="wrap-fluid">
<div class="recovery-form" id="recovery-form">
<form action="" method="POST">
<input type="password" name="password" placeholder="Nouveau mot de passe" value="<?= (!empty($_POST['password'])) ? $_POST['password'] : '' ?>">
<input type="password" name="password-confirm" placeholder="Confirmation du mot de passe" value="<?= (!empty($_POST['password-confirm'])) ? $_POST['password-confirm'] : '' ?>">
<input type="submit" name="submit" class="btn btn-purple" value="Envoyer">
</form>
</div>
<div class="recovery-image">
<img src="assets\img\undraw_secure_login_pdn4.svg" alt="Image recovery">
</div>
</section>
<?php include('src/template/footer.php');