-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwd_reset.php
113 lines (98 loc) · 3.18 KB
/
pwd_reset.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
<?php
include("header.php");
include('connection.php');
if(isset($_POST['btnsubmit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$current_password = $_POST['txtcurrent'];
$new_password = $_POST['txtnew'];
$confirm_password = $_POST['txtconfirm'];
// Validate email, name, and phone against the user table
$query = "SELECT * FROM users WHERE name=? AND email=? AND phone=?";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, "sss", $name, $email, $phone);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 1) {
if($new_password == $confirm_password) {
// Hash the new password
$hashed_password = password_hash($new_password, PASSWORD_DEFAULT);
// Update the password in the database
$update_query = "UPDATE users SET password='$new_password' WHERE email='$email'";
$update_stmt = mysqli_prepare($con, $update_query);
mysqli_stmt_bind_param($update_stmt, "ss", $hashed_password, $email);
mysqli_stmt_execute($update_stmt);
echo '<script>alert("Password updated successfully.")</script>';
echo "<script>window.location='index.php'</script>";
} else {
echo '<script>alert("Passwords do not match.")</script>';
}
} else {
echo '<script>alert("Invalid name, email, or phone number.")</script>';
}
}
?>
<style>
.table {
/* width: 100%; */
border-collapse: collapse;
margin: 0 auto; /* Center the table horizontally */
width: 50%; /* Set the width of the table */
}
.table th,
.table td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
.table th {
background-color: #f2f2f2;
}
</style>
<div id="services" class="services section">
<div class="container">
<div class="row">
<div class="col-lg-8 offset-lg-2">
<div class="section-heading">
<h4><em>Forget</em> Password</h4>
<img src="assets/images/heading-line-dec.png" alt="">
</div>
</div>
<div class="col-lg-12">
<div class="pricing-item-pro">
<form method="POST">
<table class="table">
<tr>
<th>Name</th>
<td><input required type="text" name="name"></td>
</tr>
<tr>
<th>Email</th>
<td><input required type="email" name="email"></td>
</tr>
<tr>
<th>Phone Number</th>
<td><input required type="text" name="phone"></td>
</tr>
<tr>
<th>New Password</th>
<td><input required type="password" name="txtnew"></td>
</tr>
<tr>
<th>Confirm Password</th>
<td><input required type="password" name="txtconfirm"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Update" name="btnsubmit"></td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
include("footer.php");
?>