-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_password.php
More file actions
95 lines (85 loc) · 3.69 KB
/
change_password.php
File metadata and controls
95 lines (85 loc) · 3.69 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
require_once "auth_check.php";
require_once "config/database.php";
require_once "models/User.php";
$database = new Database();
$db = $database->getConnection();
$user = new User($db);
$success = '';
$error = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$current_password = $_POST['current_password'] ?? '';
$new_password = $_POST['new_password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? '';
// Vérifier que les nouveaux mots de passe correspondent
if ($new_password !== $confirm_password) {
$error = "Les nouveaux mots de passe ne correspondent pas";
}
// Vérifier la longueur minimale
elseif (strlen($new_password) < 8) {
$error = "Le nouveau mot de passe doit faire au moins 8 caractères";
}
else {
// Tenter de mettre à jour le mot de passe
if ($user->updatePassword($_SESSION['user_id'], $current_password, $new_password)) {
$success = "Mot de passe modifié avec succès";
} else {
$error = "Le mot de passe actuel est incorrect";
}
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Changer le mot de passe</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.password-container {
max-width: 500px;
margin: 50px auto;
}
</style>
</head>
<body>
<?php include 'header.php'; ?>
<div class="container">
<div class="password-container">
<div class="card">
<div class="card-body">
<h1 class="card-title h3 mb-4">Changer le mot de passe</h1>
<?php if ($success): ?>
<div class="alert alert-success"><?php echo htmlspecialchars($success); ?></div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label for="current_password" class="form-label">Mot de passe actuel</label>
<input type="password" class="form-control" id="current_password" name="current_password" required>
</div>
<div class="mb-3">
<label for="new_password" class="form-label">Nouveau mot de passe</label>
<input type="password" class="form-control" id="new_password" name="new_password"
required minlength="8">
<div class="form-text">Le mot de passe doit faire au moins 8 caractères</div>
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">Confirmer le nouveau mot de passe</label>
<input type="password" class="form-control" id="confirm_password" name="confirm_password"
required minlength="8">
</div>
<div class="d-flex justify-content-between">
<button type="submit" class="btn btn-primary">Changer le mot de passe</button>
<a href="index.php" class="btn btn-secondary">Retour</a>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>