-
Notifications
You must be signed in to change notification settings - Fork 0
/
changePassword.php
62 lines (58 loc) · 2.36 KB
/
changePassword.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
<?php
session_start();
require('inc/functions.php');
require('inc/pdo.php');
$errors = array();
if(!empty($_GET['email']) && !empty($_GET['token'])) {
$email = urldecode($_GET['email']);
$token = urldecode($_GET['token']);
$sql = "SELECT * FROM users WHERE email = :email AND token = :token";
$query = $pdo->prepare($sql);
$query->bindValue(':email',$email,PDO::PARAM_STR);
$query->bindValue(':token',$token,PDO::PARAM_STR);
$query->execute();
$user = $query->fetch();
if(!empty($user)) {
if(!empty($_POST['submitted'])) {
$password = cleanXss('password');
$password2 = cleanXss('password2');
// password
if(!empty($password) || !empty($password2)) {
if($password != $password2) {
$errors['password'] = 'Veuillez renseigner des mot de passe identiques';
} elseif (strlen($password2) < 6) {
$errors['password'] = 'Min 6 caractères pour votre mot de passe';
}
} else {
$errors['password'] = 'Veuillez renseigner un mot de passe';
}
if(count($errors) == 0) {
$token = generateRandomString(100);
$hashpassword = password_hash($password,PASSWORD_DEFAULT);
$sql = "UPDATE users SET password = :hash, token = :token WHERE id = :id";
$query = $pdo->prepare($sql);
$query->bindValue(':hash',$hashpassword,PDO::PARAM_STR);
$query->bindValue(':token',$token,PDO::PARAM_STR);
$query->bindValue(':id',$user['id'],PDO::PARAM_INT);
$query->execute();
header('Location: login.php');
}
}
} else {
die('404');
}
} else {
die('404');
}
include('inc/header.php'); ?>
<div class="wrap2">
<form action="" method="post" novalidate>
<label for="password">Password *</label>
<input type="password" id="password" name="password" value="">
<span class="error"><?= getError($errors,'password'); ?></span>
<label for="password2">Password confirm *</label>
<input type="password" id="password2" name="password2" value="">
<input type="submit" name="submitted" value="Inscription">
</form>
</div>
<?php include('inc/footer.php');