-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreset-password.php
71 lines (61 loc) · 2.55 KB
/
reset-password.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
65
66
67
68
69
70
71
<?php
session_start();
include('inc/pdo.php');
include('inc/function.php');
$title = 'Nouveau mmot de passe';
$errors = array();
// debug($_SESSION);
$id = $_SESSION['user']['id'];
if(!empty($_GET['email']) && !empty($_GET['token'])) {
$email = $_GET['email'];
$token = $_GET['token'];
$switch2=true;
$switch='paix';
if (!empty($_POST['submittoken'])) {
$token_user = cleanXss($_POST['token']);
$Newpassword = cleanXss($_POST['Newpassword']);
$password2 = cleanXss($_POST['password2']);
$errors = ValidationText($errors,$token_user,'token',120,121);
if(!empty($Newpassword) && !empty($password2)) {
if($Newpassword != $password2) {
$errors['password2'] = 'Veuillez renseigner des mot de passe identiques.';
} elseif(mb_strlen($Newpassword) < 6) {
$errors['Newpassword'] = 'Min 6 caractères';
}
} else {
$errors['Newpassword'] = 'Veuillez renseigner vos mots de passe.';
}
if(count($errors) == 0) {
if ($token_user==$token) {
$hashPassword = password_hash($Newpassword,PASSWORD_DEFAULT);
$token = generateRandomString(120);
$sql = "UPDATE vac_users SET token=:token, password=:password WHERE id=:id";
$query = $pdo->prepare($sql);
$query->bindValue(':token',$token,PDO::PARAM_STR);
$query->bindValue(':password',$hashPassword,PDO::PARAM_STR);
$query->bindValue(':id',$id,PDO::PARAM_INT);
$query->execute();
header('Location: connexion.php');
}else {
die('not');
}
}
}
}
include('inc/header.php');?>
<?php if ($switch2==true) { ?>
<form action="" method="post" novalidate>
<!-- token -->
<input type="text" id="token" name="token" value="<?php if(!empty($_POST['token'])) { echo $_POST['token']; } ?>" placeholder="Collez-le ici">
<span class="error"><?php if(!empty($errors['token'])) { echo $errors['token']; } ?></span>
<!-- Newpassword -->
<input type="password" name="Newpassword" id="Newpassword" class="form-control" value="" placeholder="Nouveau mot de passe"/>
<span class="error"><?php if(!empty($errors['Newpassword'])) { echo $errors['Newpassword']; } ?></span>
<!-- PASSWORD2 -->
<input type="password" name="password2" id="password2" class="form-control" value="" placeholder="Confirmer votre mot de passe"/>
<span class="error"><?php if(!empty($errors['password2'])) { echo $errors['password2']; } ?></span>
<input type="submit" name="submittoken" value="Nouveau mot de passe" />
</form>
<?php } ?>
</div>
<?php include('inc/footer.php');