Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function resetPassword($token, $newPassword)
- {
- // Check if the token is valid and not expired
- $sql = 'SELECT * FROM users WHERE reset_token = :token AND reset_token_expiry > NOW()';
- $stmt = $this->pdo->prepare($sql);
- $stmt->bindParam(':token', $token);
- $stmt->execute();
- $user = $stmt->fetch();
- if ($user) {
- // Update the password and clear the reset token
- $hashedPassword = password_hash($newPassword, PASSWORD_BCRYPT);
- $sql = 'UPDATE users SET password = :password, reset_token = NULL, reset_token_expiry = NULL WHERE id = :id';
- $stmt = $this->pdo->prepare($sql);
- $stmt->bindParam(':password', $hashedPassword);
- $stmt->bindParam(':id', $user['id']);
- $stmt->execute();
- return 'Your password has been reset successfully.';
- }
- return 'Invalid or expired token.';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement