-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordReset.php
More file actions
85 lines (67 loc) · 2.39 KB
/
Copy pathPasswordReset.php
File metadata and controls
85 lines (67 loc) · 2.39 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
<?php
require('StartSession.php');
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "You are logged in as '" . $DBPassword . "' as '" . $DBName . "'<br/>";
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the entered email from the form
$entered_email = $_POST['email'];
// SQL query to check if the email exists in the database
$query = "SELECT Name_First, Name_Last, Role FROM Users WHERE Email = ?";
$emailCheck = $db->prepare($query);
$emailCheck->bind_param('s', $entered_email);
$emailCheck->execute();
$emailCheck->store_result();
$emailCheck->bind_result($firstName, $lastName, $role);
//create new password and update
if ($emailCheck->num_rows > 0) {
// Fetch the data
$emailCheck->fetch();
// Debugging: Print the fetched data
echo "New Password: " . $firstName. $role . $lastName . "<br>";
$hashedPw = password_hash(($firstName . $role . $lastName), PASSWORD_DEFAULT);
//update user password
$query = "UPDATE Users SET Password = ? WHERE Email = ?";
$pwReset = $db->prepare($query);
$pwReset->bind_param('ss', $hashedPw, $entered_email);
$pwReset->execute();
$pwReset->store_result();
}
if ($emailCheck->num_rows > 0) {
// Email exists in the database, send an email to the user
$to = $entered_email;
$subject = "Basketball League Password Reset";
$message = "Your password has been reset to 123 ";
$headers = "From: manager@CSUFBBL.com" . "\r\n" .
"CC: tjc@csu.fullerton.edu";
// Send email
if (mail($to, $subject, $message, $headers)) {
echo "Email sent successfully.";
} else {
echo "Email sending failed.";
}
} else {
// Email does not exist in the database
echo "<h3>Email not Found, Please sign up.</h3>";
require_once("newUser.html");
return;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Password Reset</title>
</head>
<h1> Basketball League Password Reset</h1>
<body>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="email">Enter your email:</label><br>
<input type="email" id="email" name="email"><br>
<br>
<input type="submit" value="Submit">
</form>
<a href="Logout.php"> Return to login</a>
</body>
</html>