-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset-password.php
142 lines (115 loc) · 5.76 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
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
<?php
// Include necessary functions and database connection
include 'Includes/dbcon.php';
session_start();
// Get email and token from the URL
$email = $_GET['email'] ?? '';
$token = $_GET['token'] ?? '';
// Validate and check if the token is valid and not expired
// (You'll need to implement this logic based on your storage mechanism)
// Display the reset password form if the token is valid
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Reset Password</title>
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="css/ruang-admin.min.css" rel="stylesheet">
</head>
<body class="bg-gradient-login">
<div class="container-login">
<div class="row justify-content-center">
<div class="col-xl-10 col-lg-12 col-md-9">
<div class="card shadow-sm my-5">
<div class="card-body p-0">
<div class="row">
<div class="col-lg-12">
<div class="login-form">
<div class="text-center">
<img src="img/logo/attnlg.jpg" style="width:100px;height:100px">
<br><br>
<h1 class="h4 text-gray-900 mb-4">Forgot Password</h1>
</div>
<?php
if (isset($_POST['submit'])) {
// Validate form data and ensure both passwords match and are strong (you can add more validation as needed)
$newPassword = $_POST['new-password'] ?? '';
$confirmPassword = $_POST['confirm-password'] ?? '';
if(empty($email) || empty($token) ){
echo "<div class='alert alert-danger' role='alert'>
Email and Token is required !
</div>";
}
else {
// Check in tbladmin table
$admin_check_query = "SELECT * FROM tbladmin WHERE emailAddress='$email' LIMIT 1";
$admin_rs = $conn->query($admin_check_query);
$admin_num = $admin_rs->num_rows;
// Check in tblclassteacher table
$teacher_check_query = "SELECT * FROM tblclassteacher WHERE emailAddress='$email' LIMIT 1";
$teacher_rs = $conn->query($teacher_check_query);
$teacher_num = $teacher_rs->num_rows;
// If email exists in tbladmin
if ($admin_num > 0) {
$tableToUpdate = 'tbladmin';
}
// If email exists in tblclassteacher
elseif ($teacher_num > 0) {
$tableToUpdate = 'tblclassteacher';
} else {
// Email not found in any expected table
echo '<div class="alert alert-danger" role="alert">Invalid email or token!</div>';
}
if (isset($tableToUpdate)) {
$token_check_query = "SELECT * FROM tbltoken WHERE emailAddress='$email' LIMIT 1";
$token_rs = $conn->query($token_check_query);
$token_num = $token_rs->num_rows;
if ($token_num > 0) {
if ($newPassword !== $confirmPassword) {
echo '<div class="alert alert-danger" role="alert">Passwords do not match. Please try again.</div>';
} elseif (strlen($newPassword) < 8) {
echo '<div class="alert alert-danger" role="alert">Password must be at least 8 characters long.</div>';
} else {
// Hash the new password using MD5
$hashedPassword = md5($newPassword);
// Update the password in the appropriate table
$updatePasswordQuery = "UPDATE $tableToUpdate SET password='$hashedPassword' WHERE emailAddress='$email'";
$updatePasswordResult = $conn->query($updatePasswordQuery);
if ($updatePasswordResult) {
// Password update successful
echo '<div class="alert alert-success" role="alert">Password reset successfully!</div>';
// ...
} else {
// Password update failed
echo '<div class="alert alert-danger" role="alert">Error updating password. Please try again.</div>';
// ...
}
}
}
}
}
}
?>
<form action="" method="post">
<!-- Password reset form fields go here -->
<div class="form-group">
<label for="new-password">New Password:</label>
<input type="password" class="form-control" id="new-password" name="new-password"
>
</div>
<!-- Confirm Password -->
<div class="form-group">
<label for="confirm-password">Confirm Password:</label>
<input type="password" class="form-control" id="confirm-password"
name="confirm-password" >
</div>
<input type="hidden" name="email" value="<?php echo htmlspecialchars($email); ?>">
<input type="hidden" name="token" value="<?php echo htmlspecialchars($token); ?>">
<input type="submit" class="btn btn-primary btn-block" value="Submit" name="submit" />
</form>
</body>
</html>