-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset_password.php
121 lines (107 loc) · 3.36 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
<?php
session_start();
// Define your database connection variables
$servername = "localhost:3306";
$username = "root";
$password = ""; // Use the correct password or empty if no password
$dbname = "shop_db"; // Use your database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die('Database connection error: ' . $conn->connect_error);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['reset_email'])) {
// Handle password reset request
$email = $conn->real_escape_string($_POST['reset_email']);
$query = "SELECT * FROM users WHERE email = '$email'";
$result = $conn->query($query);
if ($result->num_rows > 0) {
// Normally you would send an email with a reset link. Here we are skipping that step.
echo "Password reset instructions have been sent to your email.";
} else {
echo "No user found with this email.";
}
} elseif (isset($_POST['new_password'])) {
// Handle password update
$email = $conn->real_escape_string($_POST['email']);
$new_password = password_hash($_POST['new_password'], PASSWORD_BCRYPT);
$query = "UPDATE users SET password = '$new_password' WHERE email = '$email'";
if ($conn->query($query) === TRUE) {
echo "Password updated successfully. <a href='login.php'>Login here</a>";
} else {
echo "Error updating password: " . $conn->error;
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reset Password</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form method="POST" action="reset_password.php">
<h2>Reset Password</h2>
<label for="reset_email">Email:</label>
<input type="email" id="reset_email" name="reset_email" required>
<button type="submit">Send Reset Instructions</button>
</form>
<br>
<form method="POST" action="reset_password.php">
<h2>Set New Password</h2>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="new_password">New Password:</label>
<input type="password" id="new_password" name="new_password" required>
<button type="submit">Reset Password</button>
</form>
</body>
</html>
<style>
body {
font-family: 'Poppins', sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
}
form {
width: 300px;
margin: 100px auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
form h2 {
margin-bottom: 20px;
text-align: center;
}
form label {
margin: 10px 0 5px;
display: block;
}
form input {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border-radius: 5px;
border: 1px solid #ddd;
}
form button {
width: 100%;
padding: 10px;
background-color: #333;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
form button:hover {
background-color: #555;
}
</style>