Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function requestPasswordReset($email)
- {
- // Check if the email exists
- $sql = "SELECT * FROM users WHERE email = :email";
- $stmt = $this->pdo->prepare($sql);
- $stmt->bindParam(':email', $email);
- $stmt->execute();
- $user = $stmt->fetch();
- if ($user) {
- // Generate a reset token and expiry
- $token = bin2hex(random_bytes(16));
- $expiry = new DateTime('+1 hour'); // Token valid for 1 hour
- // Update the user with the reset token and expiry
- $sql = "UPDATE users SET reset_token = :token, reset_token_expiry = :expiry WHERE email = :email";
- $stmt = $this->pdo->prepare($sql);
- $stmt->bindParam(':token', $token);
- $stmt->bindParam(':expiry', $expiry->format('Y-m-d H:i:s')); <!-- Only variables should be passed by reference
- $stmt->bindParam(':email', $email);
- $stmt->execute();
- // Send email with reset link (replace with your actual domain)
- $resetLink = "https://www.luigiamorfini.local/accounts/reset_password.php?token=$token";
- mail($email, 'Password Reset Request', "Click the link to reset your password: $resetLink");
- return 'A password reset link has been sent to your email.';
- }
- return 'Email not found.';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement