-
Notifications
You must be signed in to change notification settings - Fork 0
/
forget_password_send_code.php
126 lines (109 loc) · 4.31 KB
/
forget_password_send_code.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
<?php
require('inc/links.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Process the form submission
$entered_code = filter_input(INPUT_POST, 'verification_code', FILTER_SANITIZE_NUMBER_INT);
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$new_password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
$confirm_password = filter_input(INPUT_POST, 'confirm_password', FILTER_SANITIZE_STRING);
// Default verification code
$default_code = "8548";
// Check if the entered code matches the default code
if ($entered_code !== $default_code) {
$error_message = "Invalid verification code.";
} elseif (!$email) {
$error_message = "Invalid email format.";
} elseif ($new_password !== $confirm_password) {
$error_message = "Passwords do not match.";
} else {
// Check if the email exists in the database
$query = "SELECT * FROM `user_cred` WHERE `email`=? LIMIT 1";
$user = select($query, [$email], "s");
if (mysqli_num_rows($user) == 0) {
$error_message = "Email not found.";
} else {
// Hash the new password
$hashed_password = password_hash($new_password, PASSWORD_BCRYPT);
// Update the password in the database
$update_query = "UPDATE `user_cred` SET `password`=? WHERE `email`=?";
if (update($update_query, [$hashed_password, $email], "ss")) {
$success_message = "Password has been successfully reset.";
header('Location: http://localhost/ghousebooking/index.php');
} else {
$error_message = "Failed to reset password.";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Forgot Password</title>
<!-- Bootstrap CSS (via CDN) -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<?php require('inc/header.php'); ?>
<div class="container mt-5">
<h2 class="text-center mb-4">Forgot Password</h2>
<!-- Success or Error Messages -->
<?php if (isset($success_message)) : ?>
<div class="alert alert-success" role="alert">
<?= $success_message ?>
</div>
<?php elseif (isset($error_message)) : ?>
<div class="alert alert-danger" role="alert">
<?= $error_message ?>
</div>
<?php endif; ?>
<!-- Forgot Password Form -->
<form method="POST" action="">
<div class="mb-3">
<label for="verification_code" class="form-label">Verification Code:</label>
<input
type="text"
class="form-control"
id="verification_code"
name="verification_code"
required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email:</label>
<input
type="email"
class="form-control"
id="email"
name="email"
required>
</div>
<div class="mb-3">
<label for="password" class="form-label">New Password:</label>
<input
type="password"
class="form-control"
id="password"
name="password"
required>
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">Confirm New Password:</label>
<input
type="password"
class="form-control"
id="confirm_password"
name="confirm_password"
required>
</div>
<button type="submit" class="btn btn-primary w-100">Reset Password</button>
</form>
</div>
<!-- Bootstrap JS (via CDN) + Popper JS -->
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">
</script>
</body>
</html>