-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchanger_mdp.php
67 lines (62 loc) · 2.64 KB
/
changer_mdp.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
<?php
$page_title = 'Mots de passe';
require_once('includes/load.php');
$user = current_user();
$database = new MySqli_DB();
if (isset($_POST['update'])) {
$req_fields = array('new-password', 'old-password', 'id');
validate_fields($req_fields);
if (empty($errors)) {
if (!password_verify($_POST['old-password'], current_user()['password'])) {
$session->msg('d', "Votre ancien mot de passe ne correspond pas");
redirect('changer_mdp', false);
}
$id = (int)$_POST['id'];
$new = remove_junk($db->escape(password_hash($_POST['new-password'], PASSWORD_DEFAULT, ["cost" => 12])));
$sql = $database->db_prepare("UPDATE users SET password ='{$new}' WHERE id=?");
$sql->bind_param('i', $id);
$result = $sql->execute();
$sql_result = $sql->get_result();
if ($result && $db->affected_rows($sql_result) === 1) :
$session->logout();
$session->msg('s', "Connectez-vous avec votre nouveau mot de passe.");
redirect('index', false);
else :
$session->msg('d', ' Désolé, échec de la mise à jour de votre mots de passe!');
redirect('changer_mdp', false);
endif;
} else {
$session->msg("d", $errors);
redirect('changer_mdp', false);
}
}
include_once('layouts/header.php'); ?>
<?php echo display_msg($msg); ?>
<section class="py-5">
<div class="container px-2">
<div class="bg-light rounded-3 py-5 px-4 px-md-5 mb-5">
<div class="text-center mb-5">
<div class="feature bg-primary bg-gradient text-white rounded-3 mb-3"><i class="bi bi-credit-card"></i></div>
<h1 class="fw-bolder">Changer son mots de passe</h1>
<p class="lead fw-normal text-muted mb-0">L'oubile pas hn</p>
</div>
<div class="row gx-5 justify-content-center">
<div class="col-lg-8 col-xl-6">
<form method="post" action="changer_mdp.php" class="clearfix">
<div class="form-floating mb-3">
<input class="form-control" type="text" name="old-password" placeholder="Ancien mot de passe..." required />
<label for="ancien">Ancien mot de passe</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" type="text" name="new-password" placeholder="Nouveau mot de passe..." required />
<label for="ancien">Nouveau mot de passe</label>
</div>
<input type="hidden" name="id" value="<?php echo (int)$user['id']; ?>">
<div class="d-grid"><button class="btn btn-primary btn-lg" name="update" type="submit">Modifier</button></div>
</form>
</div>
</div>
</div>
</div>
</section>
<?php include_once('layouts/footer.php'); ?>