diff --git a/forgot_password.php b/forgot_password.php new file mode 100644 index 00000000..3f642eef --- /dev/null +++ b/forgot_password.php @@ -0,0 +1,74 @@ +prepare("SELECT * FROM users WHERE email = :email"); + $stmt->bindParam(':email', $email); + $stmt->execute(); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($user) { + // Generate a unique token + $token = bin2hex(random_bytes(50)); + + // Store the token in the password_resets table + $stmt = $db->prepare("DELETE FROM password_resets WHERE email = :email"); + $stmt->bindParam(':email', $email); + $stmt->execute(); + + $stmt = $db->prepare("INSERT INTO password_resets (email, token) VALUES (:email, :token)"); + $stmt->bindParam(':email', $email); + $stmt->bindParam(':token', $token); + $stmt->execute(); + + // Send the password reset email + $reset_link = "http://" . $_SERVER['HTTP_HOST'] . "/reset_password.php?token=" . $token; + $subject = "Password Reset Request"; + $body = "Click on this link to reset your password: ''' . $reset_link . '''"; + + MailService::sendMail($email, $subject, $body, strip_tags($body)); + + $message = "If an account with that email exists, a password reset link has been sent."; + } else { + $message = "If an account with that email exists, a password reset link has been sent."; + } +} + +include 'header.php'; +?> + +
Please enter your email address. You will receive a link to create a new password via email.
+ +