-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset-password.php
83 lines (72 loc) · 2.73 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
72
73
74
75
76
77
78
79
80
81
82
83
<?php
include_once 'header.php';
if (isset($_GET["user"])) {
$username = htmlspecialchars(urldecode($_GET["user"]));
?>
<section class="reset-password-form">
<h2>Reset Password for <?php echo $username; ?></h2>
<form action="includes/reset-password.inc.php" method="post">
<input type="hidden" name="uid" value="<?php echo $username; ?>">
<div>
<input type="password" name="newpwd" id="newpwd" placeholder="New password..." onkeyup="validatePassword()">
<span id="pwd-error"></span>
</div>
<div>
<input type="password" name="newpwdrepeat" id="newpwdrepeat" placeholder="Repeat new password..." onkeyup="validatePassword()">
<span id="pwdrepeat-error"></span>
</div>
<div>
<button type="submit" name="reset-password" value="Reset Password">Reset Password</button>
</div>
</form>
<?php
if (isset($_GET["error"])) {
echo "<div class='error-message'>";
$error = $_GET["error"];
if ($error == "emptyinput") {
echo "<p>Please fill all fields.</p>";
} else if ($error == "minlength") {
echo "<p>Password must be at least 8 characters long.</p>";
} else if ($error == "passwordsdonotmatch") {
echo "<p>Passwords don't match.</p>";
} else if ($error == "stmtfailed") {
echo "<p>Something went wrong. Please try again.</p>";
}
echo "</div>";
}
?>
</section>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('input').keyup(function() {
let field = $(this).attr('name');
if (field === 'newpwd' || field === 'newpwdrepeat') {
validatePassword();
}
});
});
function validatePassword() {
let pwd = $('#newpwd').val();
let pwdrepeat = $('#newpwdrepeat').val();
$.ajax({
url: 'signup_onkeyup/pwd_ajax.php',
type: 'POST',
data: {
pwd: pwd,
pwdrepeat: pwdrepeat
},
success: function(response) {
// Parse the JSON response
let data = JSON.parse(response);
// Update error messages
$('#pwd-error').text(data.pwd);
$('#pwdrepeat-error').text(data.pwdrepeat);
}
});
}
</script>
<?php
}
include_once 'footer.php';
?>