How to disable lost password feature
-
Problem:
anyone who goes to:
https://www.yourblog.com/wp-login.php?action=lostpassword
can attempt to retrieve a password.
If this behavior is unwanted, here’s a proposed solution for disabling the lost password feature in 2.8.4.
1. comment out code in wp-login.php, lines 326 and following, and add redirect:
case 'retrievepassword' : /* if ( $http_post ) { $errors = retrieve_password(); if ( !is_wp_error($errors) ) { wp_redirect('wp-login.php?checkemail=confirm'); exit(); } } if ( isset($_GET['error']) && 'invalidkey' == $_GET['error'] ) $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.')); do_action('lost_password'); login_header(__('Lost Password'), '<p class="message">' . __('Please enter your username or e-mail address. You will receive a new password via e-mail.') . '</p>', $errors); $user_login = isset($_POST['user_login']) ? stripslashes($_POST['user_login']) : ''; */ header("location: https://www.yourblog.com/"); ?>
2. comments out links to ‘lost your password?’ in wp-login, lines 530 and following:
<a href="<?php //echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php //_e('Password Lost and Found') ?>"><?php //_e('Lost your password?') ?></a> <?php else : ?> <a href="<?php //echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php //_e('Password Lost and Found') ?>"><?php //_e('Lost your password?') ?></a> <?php endif; ?>
3. modify code in wp-includes/users.php lines 88 and following so ‘lost your password?’ link does not appear after failed login attempt.
if ( !$userdata ) { //return new WP_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), site_url('wp-login.php?action=lostpassword', 'login'))); return new WP_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid username.'), site_url('', ''))); } $userdata = apply_filters('wp_authenticate_user', $userdata, $password); if ( is_wp_error($userdata) ) { return $userdata; } if ( !wp_check_password($password, $userdata->user_pass, $userdata->ID) ) { //return new WP_Error('incorrect_password', sprintf(__('<strong>ERROR</strong>: Incorrect password. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), site_url('wp-login.php?action=lostpassword', 'login'))); return new WP_Error('incorrect_password', sprintf(__('<strong>ERROR</strong>: Incorrect password.'), site_url('', ''))); }
suggestions for improvement? alternatives?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to disable lost password feature’ is closed to new replies.