【问题标题】:Wordpress Visibility: Password Protected pages (case insensitive?)Wordpress 可见性:受密码保护的页面(不区分大小写?)
【发布时间】:2014-11-18 15:30:03
【问题描述】:

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

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

任何人都可以在这里解释一下吗?

亲切的问候,

肖恩

【问题讨论】:

  • 我不太明白(也许只是我自己)但问题到底出在哪里?区分大小写是不是很糟糕?
  • 当我希望密码不区分大小写时,密码是区分大小写的,也就是说,您可以像 (password) 或 (PASSWORD) 一样输入它,它们都可以工作。希望这是有道理的:)

标签: php wordpress passwords


【解决方案1】:

对此的快速解决方案是安装插件:

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

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

我也找到了这个here

编辑显示实际代码(确认工作,只是不适用于受密码保护的页面,因为它使用其他功能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 );

编辑:

我查看了代码,发现更好的方法是对表单进行快速而肮脏的 hack,强制所有插入的字符为小写。

将以下代码添加到functions.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' );

请注意,现在您只能在管理中插入小写密码,否则将无法正常工作。

代码所做的是onChange将插入的单词转换为小写,但如果你输入的密码是大写字母,它就不起作用了。

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

您可以按照此link 将黑客作为插件进行检查

【讨论】:

  • 感谢您的反馈,我已经用工作代码更新了答案。
  • 底部解决方案对我有用,开箱即用。谢谢。
  • 我只需要在受密码保护的页面上使密码不区分大小写,因此我在 post-template.php 中插入了此答案中提到的 javascript,它就像一个魅力。
【解决方案2】:

我也想弄清楚这一点。我尝试了 nunorbatista 为 functions.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' );

【讨论】:

    猜你喜欢
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多