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'; ?>

Forgot Password

Please enter your email address. You will receive a link to create a new password via email.