0

I need to change the information given on Wordpress' Login page and the Lost password page so that hackers cannot easily see if a username or email is associated with an existing account.

At the moment Wordpress gives away way too much useful information. On the Login page it tells you if the username is wrong or if the password is wrong. I need this to just say something like 'Login failed' - this will not provide the hacker with valuable information about whether they have an existing username or email. Then on the Lost Password, I just want it to say somethink like 'Please check your email, if the username or email exists we will send you a link' - or something like that!

Thanks in advance for any help!

1 Answer 1

0

Add the following to your functions.php file.

function my_custom_error_messages() {
    global $errors;
    $err_codes = $errors->get_error_codes();

    // Invalid username.
    if ( in_array( 'invalid_username', $err_codes ) ) {
        $error = '<strong>ERROR</strong>: Custom Message Here';
    }

    // Incorrect password.
    if ( in_array( 'incorrect_password', $err_codes ) ) {
        $error = '<strong>ERROR</strong>: Another Custom Message Here';
    }

    return $error;
}

add_filter( 'login_errors', 'my_custom_error_messages');

You can write a separate error message for each or combine the if statements if you only want one message. Like this.

if ( in_array( 'invalid_username', $err_codes ) || in_array( 'incorrect_password', $err_codes ) ) {
    $error = '<strong>ERROR</strong>: Custom Message Here';
}
1
  • That seems perfect for the Login page! But on the 'lost password' page, I don't want to display any 'error' at all... at the moment when you enter a real user or email address you get 'Check your email for the confirmation link.' with a blue bar, not a red one. So ideally I want to just edit this message - is that possible? Showing an error, i.e. a red bar just confirms that the username or email doesn't exist
    – the_lar
    Feb 5, 2019 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.