安全问题-显示常规自定义登录错误消息

时间:2019-02-05 作者:the_lar

我需要更改Wordpress登录页面和丢失密码页面上提供的信息,以便黑客无法轻松查看用户名或电子邮件是否与现有帐户关联。

目前Wordpress泄露了太多有用的信息。在登录页面上,它会告诉您用户名是否错误或密码是否错误。我需要这样说,比如“登录失败”,这不会为黑客提供关于他们是否有现有用户名或电子邮件的有价值信息。然后在丢失的密码上,我只想说“请检查您的电子邮件,如果用户名或电子邮件存在,我们会给您发送一个链接”之类的话!

提前感谢您的帮助!

1 个回复
SO网友:RiddleMeThis

将以下内容添加到函数中。php文件。

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\');
如果只需要一条消息,可以为每条消息编写单独的错误消息,也可以合并if语句。像这样。

if ( in_array( \'invalid_username\', $err_codes ) || in_array( \'incorrect_password\', $err_codes ) ) {
    $error = \'<strong>ERROR</strong>: Custom Message Here\';
}

相关推荐

如何:使用WordPress‘Hooks’在自定义帖子类型上显示ACF[字段]?

Sub-questions:i) Which files/templates need to be copied to the child theme folder, other than function.php and style.css?ii) What actions/filters/ should be used and where should this code be inserted?抱歉,如果下面的措辞不准确,我是WP初学者。我最近在本地主机上安装了Customizer 4.0.8[作为