WordPress可见性:受密码保护的页面(不区分大小写?


Wordpress Visibility: Password Protected pages (case insensitive?)

我正在建立一个网站,该网站为特权客户提供受保护的空间,他们在其中输入密码并获得独家优惠等。我已将可见性设置更改为密码保护并输入了密码。

我现在的问题是它区分大小写!而且我找不到任何地方如何改变这一点。肯定有办法吗?

谁能在这里透露任何信息?

亲切问候

肖恩

快速的解决方案是安装一个插件:

https://wordpress.org/plugins/case-insensitive-passwords/installation/

这个似乎可以解决问题,并说它与版本4.0兼容

我也在这里找到了这个

编辑显示实际代码(确认有效,只是不适用于受密码保护的页面,因为它使用其他功能 http://codex.wordpress.org/Function_Reference/post_password_required):

<?php
if ( !function_exists('wp_set_password') ) {
    function wp_set_password( $password, $user_id ) {
        global $wpdb;
        $password = strtolower( $password );
        $hash = wp_hash_password($password);
        $wpdb->update($wpdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $user_id) );
        wp_cache_delete($user_id, 'users');
    }
}
if ( !function_exists('wp_hash_password') ) {
    function wp_hash_password($password) {
        global $wp_hasher;
        $password = strtolower( $password );
        if ( empty($wp_hasher) ) {
            require_once( ABSPATH . 'wp-includes/class-phpass.php');
            // By default, use the portable hash from phpass
            $wp_hasher = new PasswordHash(8, TRUE);
        }
        return $wp_hasher->HashPassword($password);
    }
}
function case_insensitive_check_password( $check, $password, $hash, $user_id ) {
    global $wp_hasher;
    if ( !$check ) {
        if ( empty($wp_hasher) ) {
            require_once( ABSPATH . 'wp-includes/class-phpass.php');
            // By default, use the portable hash from phpass
            $wp_hasher = new PasswordHash(8, TRUE);
        }
        $password = strtolower( $password );
        $check = $wp_hasher->CheckPassword($password, $hash);
    }
    return $check;
}
add_filter( 'check_password', 'case_insensitive_check_password', 10, 4 );

编辑:

我已经查看了代码,发现更好的方法是在表单上进行快速而肮脏的黑客攻击,强制所有插入的字符为小写。

将下面的代码添加到函数.php文件中:

function my_password_form() {
    global $post;
    $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
    $o = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
    ' . __( "To view this protected post, enter the password below:" ) . '
    <label for="' . $label . '">' . __( "Password:" ) . ' </label>
    <input name="post_password" onChange="javascript:this.value=this.value.toLowerCase();" id="' . $label . '" type="password" size="20" maxlength="20" />
    <input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
    </form>
    ';
    return $o;
}
add_filter( 'the_password_form', 'my_password_form' );

考虑到现在您只能在管理中插入小写密码,否则它将不起作用。

代码正在执行的操作是将插入的单词转换为小写,但是如果您输入带有大写字母的密码,则无法正常工作。

例如:受密码保护的页面密码:香蕉 ->插入的密码:香蕉=它将香蕉与香蕉进行比较,因为插入的将是小写的。

您可以通过以下链接将黑客作为插件进行检查

我也

试图弄清楚这一点。我尝试了 nunorbatista 为函数提供的代码.php,但它不起作用。我找到了另一个有答案的问题,解决方案几乎相同,只是他们使用"onkeypress"而不是"onChange"。这是他的代码,其中包含此小更改:

function my_password_form() {
    global $post;
    $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
    $o = '<form action="' . esc_url( site_url('wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
    ' . __( "To view this protected post, enter the password below:" ) . '
    <label for="' . $label . '">' . __( "Password:" ) . ' </label>
    <input name="post_password" onkeypress="javascript:this.value=this.value.toLowerCase();" id="' . $label . '" type="password" size="20" maxlength="20" />
    <input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
    </form>
    ';
    return $o;
}
add_filter( 'the_password_form', 'my_password_form' );