-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_pass.php
More file actions
212 lines (190 loc) · 9.76 KB
/
change_pass.php
File metadata and controls
212 lines (190 loc) · 9.76 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
if(!isset($_SESSION)) {
session_start();
}
include "auth.php";
include "header_voter.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SecureVote - Change Password</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Animate.css -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f8f9fa;
}
.password-card {
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.card-header {
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
}
.password-strength {
height: 5px;
margin-top: 5px;
background-color: #e9ecef;
border-radius: 3px;
}
.form-control:focus {
box-shadow: 0 0 0 0.25rem rgba(42, 82, 152, 0.25);
border-color: #2a5298;
}
.input-group-text {
background-color: #f8f9fa;
}
</style>
</head>
<body>
<div class="container my-5">
<div class="row justify-content-center">
<div class="col-md-6 col-lg-5">
<div class="card password-card animate__animated animate__fadeIn">
<div class="card-header text-white">
<h3 class="card-title mb-0 text-center">
<i class="fas fa-key me-2"></i>Change Password
</h3>
</div>
<div class="card-body p-4">
<!-- User Greeting -->
<?php if(isset($nam) && !empty($nam)): ?>
<div class="alert alert-info d-flex align-items-center">
<i class="fas fa-user-circle me-2 fs-4"></i>
<span><?php echo htmlspecialchars($nam); ?></span>
</div>
<?php endif; ?>
<!-- Error Message -->
<?php if(isset($error) && !empty($error)): ?>
<div class="alert alert-danger alert-dismissible fade show">
<i class="fas fa-exclamation-circle me-2"></i>
<?php echo htmlspecialchars($error); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<!-- Password Change Form -->
<form action="change_pass_action.php" method="post" id="myform" class="needs-validation" novalidate>
<div class="mb-3">
<label for="cpassword" class="form-label">Current Password</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-lock"></i></span>
<input type="password" class="form-control" id="cpassword" name="cpassword" required>
<button class="btn btn-outline-secondary toggle-password" type="button">
<i class="fas fa-eye"></i>
</button>
</div>
<div class="invalid-feedback">Please enter your current password</div>
</div>
<div class="mb-3">
<label for="npassword" class="form-label">New Password</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-key"></i></span>
<input type="password" class="form-control" id="npassword" name="npassword" required
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}"
title="Must contain at least 8 characters, including uppercase, lowercase, and number">
<button class="btn btn-outline-secondary toggle-password" type="button">
<i class="fas fa-eye"></i>
</button>
</div>
<div class="invalid-feedback">
Password must be at least 8 characters with uppercase, lowercase, and number
</div>
<div class="password-strength mt-2">
<div id="password-strength-bar" class="progress-bar" role="progressbar"></div>
</div>
<small class="text-muted">Minimum 8 characters with uppercase, lowercase, and number</small>
</div>
<div class="mb-4">
<label for="cnpassword" class="form-label">Confirm New Password</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-check-circle"></i></span>
<input type="password" class="form-control" id="cnpassword" name="cnpassword" required>
<button class="btn btn-outline-secondary toggle-password" type="button">
<i class="fas fa-eye"></i>
</button>
</div>
<div class="invalid-feedback">Please confirm your new password</div>
<div id="password-match-feedback" class="mt-1 small"></div>
</div>
<div class="d-grid gap-2">
<button type="submit" name="cpass" value="UPDATE" class="btn btn-primary btn-lg">
<i class="fas fa-sync-alt me-2"></i>Update Password
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap JS Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Toggle password visibility
document.querySelectorAll('.toggle-password').forEach(button => {
button.addEventListener('click', function() {
const input = this.closest('.input-group').querySelector('input');
const icon = this.querySelector('i');
if (input.type === 'password') {
input.type = 'text';
icon.classList.replace('fa-eye', 'fa-eye-slash');
} else {
input.type = 'password';
icon.classList.replace('fa-eye-slash', 'fa-eye');
}
});
});
// Password strength indicator
const passwordInput = document.getElementById('npassword');
const strengthBar = document.getElementById('password-strength-bar');
const confirmPasswordInput = document.getElementById('cnpassword');
const matchFeedback = document.getElementById('password-match-feedback');
passwordInput.addEventListener('input', function() {
const strength = checkPasswordStrength(this.value);
strengthBar.style.width = strength.percentage + '%';
strengthBar.className = 'progress-bar ' + strength.class;
});
confirmPasswordInput.addEventListener('input', function() {
if (this.value !== passwordInput.value) {
matchFeedback.textContent = 'Passwords do not match';
matchFeedback.style.color = 'red';
} else {
matchFeedback.textContent = 'Passwords match';
matchFeedback.style.color = 'green';
}
});
function checkPasswordStrength(password) {
let strength = 0;
if (password.length >= 8) strength++;
if (/[A-Z]/.test(password)) strength++;
if (/[0-9]/.test(password)) strength++;
if (/[^A-Za-z0-9]/.test(password)) strength++;
const percentage = Math.min(strength * 25, 100);
let colorClass = 'bg-danger'; // red
if (strength >= 3) colorClass = 'bg-warning'; // yellow
if (strength >= 5) colorClass = 'bg-success'; // green
return { percentage, class: colorClass };
}
// Form validation
const form = document.getElementById('myform');
form.addEventListener('submit', function(event) {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
</script>
<?php include "footer.php"; ?>
</body>
</html>