-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgot.php
52 lines (42 loc) · 1.6 KB
/
forgot.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
<?php
session_start();
if(isset($_POST["login"])) {
// Your existing login code here
}
if(isset($_POST["forgot_password"])) {
$useremail = $_POST['useremail'];
// Check if the email exists in the database
$db = mysqli_connect("127.0.0.1:3308", "root", "", "car_showroom");
$query = mysqli_query($db, "SELECT * FROM customer WHERE email = '".$email."'");
$numrows = mysqli_num_rows($query);
if($numrows == 1) {
// Generate a unique token
$token = bin2hex(random_bytes(32));
// Store the token in the database with the user's email and timestamp
$timestamp = time();
mysqli_query($db, "INSERT INTO password_reset (email, token, timestamp) VALUES ('$useremail', '$token', '$timestamp')");
// Send an email to the user with a link to reset their password
$reset_link = "http://yourwebsite.com/reset_password.php?token=".$token;
$subject = "Password Reset";
$message = "Click the following link to reset your password: ".$reset_link;
// Use mail() function to send the email
echo "An email has been sent to your email address with instructions to reset your password.";
} else {
echo "No user found with that email address.";
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Forgot Password</title>
</head>
<body>
<h2>Forgot Password</h2>
<form method="post" action="">
<label>Email</label>
<input type="email" name="useremail" required>
<button type="submit" name="forgot_password">Reset Password</button>
</form>
</body>
</html>