我们当前的系统(不使用Wordpress)有1000个用户需要移植到Wordpress.我们遇到的问题是密码不能保持不变.
在我们当前的系统中,密码保存为:
md5( md5( $password ) . USER_SALT ); // USER_SALT is a defined constant
Run Code Online (Sandbox Code Playgroud)
显然不是最好的,但不是最糟糕的......
我们需要制作我们目前在WP中工作的密码哈希值.有没有办法我们可以先通过此设置运行所有新密码,然后通过WP自己的散列运行?
我知道你可以加入以下功能:
function my_hash_password($password){
    return md5( md5( $password ) . USER_SALT );
}
add_action('wp_hash_password', 'my_hash_password' );
Run Code Online (Sandbox Code Playgroud)
由于某些原因,它也没有完全发挥作用.
当然其他人之前已经经历过这个.
谢谢.
编辑!!!!
到目前为止,存在一些混乱.我不是要求不散列我们拥有的哈希密码.我所说的是,对于我们当前的系统,密码看起来像:
Password:  password
Hash function: md5( md5( $password ) . USER_SALT );
Output: d372f9c033e9c358b111ff265e080d3a
Run Code Online (Sandbox Code Playgroud)
我想'也许'能够将上面的哈希值并将其提供给本机WP密码哈希,以便:
d372f9c033e9c358b111ff265e080d3a
Run Code Online (Sandbox Code Playgroud)
成为...
$P$BdrwxndTzgTVHUozGpQ9TEMYd6mpTw0
Run Code Online (Sandbox Code Playgroud)
在它完成它们的功能之后.
然后,当用户登录时,我们通过我们的功能发回他们的纯文本密码,然后通过WP发送匹配.
////////////////////////
更新!!!
///////////////////////
试图覆盖WP中可插入的'wp_check_password'函数,但由于某种原因它似乎不起作用.
function my_check_password($password, $hash, $user_id = '') {
    global $wp_hasher;
    if ( $hash == md5( md5( $password ) . USER_SALT ) ){
        if ( $user_id ) {
        $check = true;
        wp_set_password($password, $user_id);
        $hash = wp_hash_password($password);
      }
      return apply_filters( 'check_password', $check, $password, $hash, $user_id );
    }
    // If the hash is still md5...
    elseif ( strlen($hash) <= 32 ) {
        $check = hash_equals( $hash, md5( $password ) );
        if ( $check && $user_id ) {
            // Rehash using new hash.
            wp_set_password($password, $user_id);
            $hash = wp_hash_password($password);
        }
        return apply_filters( 'check_password', $check, $password, $hash, $user_id );
    }
    // If the stored hash is longer than an MD5, presume the
    // new style phpass portable hash.
    if ( empty($wp_hasher) ) {
        require_once( ABSPATH . WPINC . '/class-phpass.php');
        // By default, use the portable hash from phpass
        $wp_hasher = new PasswordHash(8, true);
    }
    $check = $wp_hasher->CheckPassword($password, $hash);
    /** This filter is documented in wp-includes/pluggable.php */
    return apply_filters( 'check_password', $check, $password, $hash, $user_id );
}
add_action('wp_check_password', 'my_check_password' );
Run Code Online (Sandbox Code Playgroud)
有人有什么想法吗?
实现此目的最简单的方法是创建一个插件。如果不创建具有该功能的插件,则无法完全覆盖 WP 功能。您可以完全覆盖的函数位于“pluggable.php”文件中。这应该是不言自明的,您需要创建一个“插件”来覆盖它们。
我所要做的就是创建一个简单的插件:
添加插件文件:
/*
Plugin Name: My Password Updater
Plugin URI: Your Website
Description: Checks both new and old passwords and updates old passwords
Version: 0.0.1
Author: Your Name
Author URI: 
License: 
*/
if( ! function_exists( 'wp_check_password' ) ){
    function wp_check_password($password, $hash, $user_id = '') {
        global $wp_hasher;
        // Put whatever code from your old password hash check here
        // In my case it was the following...
        if ( $hash == md5( md5( $password ) . 'MY USER SALT' ) ){
            if ( $user_id ) {
                $check = true;
                wp_set_password($password, $user_id);
                $hash = wp_hash_password($password);
            }
            return apply_filters( 'check_password', $check, $password, $hash, $user_id );
        }
        // The code below is from the original function
        elseif ( strlen($hash) <= 32 ) {
            $check = hash_equals( $hash, md5( $password ) );
            if ( $check && $user_id ) {
                wp_set_password($password, $user_id);
                $hash = wp_hash_password($password);
            }
            return apply_filters( 'check_password', $check, $password, $hash, $user_id );
        }
        if ( empty($wp_hasher) ) {
            require_once( ABSPATH . WPINC . '/class-phpass.php');
            $wp_hasher = new PasswordHash(8, true);
        }
        $check = $wp_hasher->CheckPassword($password, $hash);
        return apply_filters( 'check_password', $check, $password, $hash, $user_id );
    }
}
Run Code Online (Sandbox Code Playgroud)|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           755 次  |  
        
|   最近记录:  |