wordpress 隐藏账号,保护安全

wordpress万年漏洞 author漏洞 ,官方应该不打算修复。下面提供方法

http://www.yoursite. com/?author=1,多用户的可以把1变为2、3、4、5等,就可以在地址栏查看到各个用户名。

知道了后台登陆地址和用户名后,剩下的就是用暴力破解密码了,如果没有任何防护的话,成功指数相当高。

为了保障我们的后台安全,建议安装一个Limit Login Attempts插件,来限制强行登陆的次数,同时修改后台登陆地址和隐藏我们的用户名。

修改后台登陆地址:

在所用主题的functions.php文件的?>前面添加以下代码即可实现。

//使用昵称替换用户名,通过用户ID进行查询
add_filter( 'request', 'wpdaxue_request' );
function wpdaxue_request( $query_vars )
{
    if ( array_key_exists( 'author_name', $query_vars ) ) {
        global $wpdb;
        $author_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='nickname' AND meta_value = %s", $query_vars['author_name'] ) );
        if ( $author_id ) {
            $query_vars['author'] = $author_id;
            unset( $query_vars['author_name'] );    
        }
    }
    return $query_vars;
}
 
//使用昵称替换链接中的用户名
add_filter( 'author_link', 'wpdaxue_author_link', 10, 3 );
function wpdaxue_author_link( $link, $author_id, $author_nicename )
{
    $author_nickname = get_user_meta( $author_id, 'nickname', true );
    if ( $author_nickname ) {
        $link = str_replace( $author_nicename, $author_nickname, $link );
    }
    return $link;
}

PS:昵称里一定用英文名

此处评论已关闭