-
Notifications
You must be signed in to change notification settings - Fork 0
/
forgot_password.php
129 lines (108 loc) · 4.17 KB
/
forgot_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
122
123
124
125
126
127
128
129
<?php
require 'db/db_connect.php';
$conn = $con;
if (isset($_POST['email'])) {
$email = $_POST['email'];
$token = bin2hex(random_bytes(50)); // Generate random token
$expires = date("Y-m-d H:i:s", strtotime('+1 hour')); // Token valid for 1 hour
// Check if the email exists in the users table
$query = "SELECT * FROM accounts WHERE email = ?";
$stmt = $conn->prepare(query: $query);
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// Update the user table with the reset token and expiration date
$update = "UPDATE accounts SET reset_token = ?, token_expiration = ? WHERE email = ?";
$stmt = $conn->prepare($update);
$stmt->bind_param("sss", $token, $expires, $email);
$stmt->execute();
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: Shotstreak <shotstreak@shotstreak.ca> \r\n";
// Send reset email (Example)
$reset_link = "https://localhost/shotstreak/reset_password.php?token=$token";
$message = "
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Invitation to Join Shotstreak</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.email-container {
max-width: 600px;
margin: 0 auto;
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.email-header {
text-align: center;
padding-bottom: 20px;
}
.email-header h1 {
color: #ff6b6b;
}
.email-body {
color: #333;
line-height: 1.6;
}
.email-body p {
margin: 10px 0;
}
.cta-button {
display: inline-block;
padding: 10px 20px;
background-color: #ff6b6b;
color: #ffffff;
text-decoration: none;
border-radius: 5px;
margin-top: 20px;
margin-bottom: 20px;
font-size: 16px;
}
.cta-button:hover {
background-color: #e65a5a;
}
.footer {
text-align: center;
color: #999;
font-size: 12px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class='email-container'>
<div class='email-header'>
<h1>Reset Your Shotstreak Password</h1>
<img title='logo' src='https://shotstreak.simonsites.com/assets/isoLogo.svg' alt='Logo' height='200' width='200'>
</div>
<div class='email-body'>
<p><b>Reset Your Shotstreak Password</b></p>
<a href='$reset_link' class='cta-button'>Reset Password</a>
<p>If you did not expect this email, feel free to ignore it.</p>
</div>
<div class='footer'>
<p>© 2024 Shotstreak. All rights reserved.</p>
</div>
</div>
</body>
</html>
";
mail($email, "Shotstreak Password Reset", $message, $headers);
header("Location: success.php?b=reset.php");
} else {
header("Location: error.php?a=User Not Found&b=login.php");
exit();
}
}