-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforget.php
More file actions
195 lines (167 loc) · 7.36 KB
/
forget.php
File metadata and controls
195 lines (167 loc) · 7.36 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
<?php
// Include the database connection file
include 'database.php';
$login_error = "";
$password_error = "";
$login = ""; // Initialize login variable to retain user input
// Check if the form has been submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$login = $_POST['login']; // Capture the login input
$new_password = $_POST['new-password'];
$retype_password = $_POST['retype-password'];
// Prepare SQL statement to check if the user exists
$sql = "SELECT * FROM customers WHERE Username = ? OR Email = ? OR Phone = ?";
$stmt = $connect->prepare($sql);
$stmt->bind_param("sss", $login, $login, $login);
$stmt->execute();
$result = $stmt->get_result();
// Check if any rows were returned
if ($result->num_rows === 0) {
// User not found, display error message
$login_error = "User doesn't exist.";
} elseif ($new_password !== $retype_password) {
// Check if the new password and retype password match
$password_error = "Passwords do not match."; // Set password error message
} else {
// User exists, proceed with password reset
// Hash the new password using SHA-256
$hashed_password = hash('sha256', $new_password);
// Update the user's password in the database
$sql_update = "UPDATE customers SET Password = ? WHERE Username = ? OR Email = ? OR Phone = ?";
$stmt_update = $connect->prepare($sql_update);
$stmt_update->bind_param("ssss", $hashed_password, $login, $login, $login);
$stmt_update->execute();
// Password successfully updated, redirect to index.php
echo '
<div class="loading-screen">
<div class="log-in">Account Password <br> Change successfully! </div>
<div class="loading-image">
<img src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" alt="Loading Image">
</div>
</div>
<style>
.loading-screen {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: linear-gradient(#E7E7E7, #818181, #9A9B84);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
color: black;
text-align: center;
font-size: 45px;
margin-bottom:15px;
z-index: 1000;
}
.log-in {
border: black solid 1px;
border-radius: 25px;
padding: 10px;
background-color: #57573f;
margin-bottom: 0px;
}
.loading-image img {
width: 100px;
height: 100px;
animation: spinY 1s linear infinite;
margin: 20px auto;
margin-top: 100px;
z-index: 9999;
}
@keyframes spinY {
0% { transform: rotateY(0deg); }
100% { transform: rotateY(360deg); }
}
</style>
<script>
setTimeout(function() {
window.location.href = "index.php";
}, 3000);
</script>';
exit();
// Close the update statement
$stmt_update->close();
}
// Close the prepared statement
$stmt->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forget Password</title>
<link rel="stylesheet" href="forget.css">
<link rel="shortcut icon" href="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Beau+Rivage&display=swap" rel="stylesheet">
</head>
<body>
<header>
<div>
<a class="logo-div" href="index.php" target="_self" onclick="showLoadingScreen('Loading...')">
<img src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" alt="Logo">
<h1>Happy Ending</h1>
</a>
</div>
<nav>
<ul>
<li><a onclick="showLoadingScreen('Loading...');" href="" target="_self">OUR PRODUCT</a></li>
<li><a onclick="showLoadingScreen('Loading...')" href="" target="_self">HELP & SUPPORT</a></li>
<li><a onclick="showLoadingScreen('Loading...')" href="" target="_self">GUEST</a></li>
</ul>
</nav>
</header>
<main>
<img class="login-logo" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" alt="LogIn Logo">
<section class="login-form">
<h2>Password Reset</h2>
<hr>
<!-- Display login error if exists -->
<?php if (!empty($login_error)): ?>
<p class="error"><?= htmlspecialchars($login_error) ?></p>
<?php endif; ?>
<!-- Display password mismatch error if exists -->
<?php if (!empty($password_error)): ?>
<p class="error"><?= htmlspecialchars($password_error) ?></p>
<?php endif; ?>
<form action="forget.php" method="post">
<label for="login">Username, Email, or Phone:</label>
<input type="text" id="login" name="login" placeholder="Username, Email, or Phone" value="<?= htmlspecialchars($login) ?>" required><br/>
<label for="new-password">New Password:</label>
<input type="password" id="new-password" name="new-password"
pattern="^(?=.*[0-9].*[0-9])[a-zA-Z0-9]{8,}$"
title="Password must be at least 8 characters long and contain at least 2 numbers."
placeholder="New Password" required><br/>
<label for="retype-password">Retype Password:</label>
<input type="password" id="retype-password" name="retype-password"
pattern="^(?=.*[0-9].*[0-9])[a-zA-Z0-9]{8,}$"
title="Password must match the criteria."
placeholder="Retype Password" required><br/>
<div class="submit">
<input type="submit" value="Reset Password">
</div>
</form>
</section>
</main>
<footer>
<p class="copyright">© 2024 Happy Ending. All rights reserved.</p>
<nav>
<ul>
<li class="about-us"><a href="#">ABOUT US</a></li>
<li><a href="https://www.facebook.com" target="_blank"><img class="icons-picture" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1724068194/angoienw2wu8c1aqdrge.png" alt="FB-logo"></a></li>
<li><a href="https://www.instagram.com" target="_blank"><img class="icons-picture" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726891138/zzzgspgokfq1sbc9sjmu.webp" alt="IG-logo"></a></li>
<li><a href="https://www.x.com" target="_blank"><img class="icons-picture" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726890890/edvvrnyg1wewlm1onmzs.png" alt="X-logo"></a></li>
</ul>
</nav>
</footer>
<script src="forget.js"></script> <!-- Link to the new JavaScript file -->
</body>
</html>