我们当前的系统(未使用 Wordpress)有 1000 多个用户,我们需要将其移植到 Wordpress。我们遇到的问题是密码不能保持不变。
在我们当前的系统中,密码保存在:
md5( md5( $password ) . USER_SALT ); // USER_SALT is a defined constant
显然不是最好的,但也不是最差的...
我们需要使我们目前拥有的这些密码哈希也能在 WP 中使用。有没有一种方法可以让我们先通过此设置运行所有新密码,然后再通过 WP 自己的哈希算法?
我知道您可以挂接到以下函数:
function my_hash_password($password){
return md5( md5( $password ) . USER_SALT );
}
add_action('wp_hash_password', 'my_hash_password' );
出于某种原因,这也没有完全发挥作用。
肯定有人已经经历过这个了。
谢谢。
编辑!!!!
到目前为止还有一些困惑。我不要求取消散列我们拥有的散列密码。我的意思是,在我们当前的系统中,密码如下所示:
Password: password
Hash function: md5( md5( $password ) . USER_SALT );
Output: d372f9c033e9c358b111ff265e080d3a
我想“也许”能够获取上面的哈希并将其提供给 native WP 密码哈希器,以便:
d372f9c033e9c358b111ff265e080d3a
变成...
$P$BdrwxndTzgTVHUozGpQ9TEMYd6mpTw0
在它完成它们的功能之后。
然后,当用户登录时,我们通过我们的函数发回他们的明文密码,然后通过 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' );
有人有什么想法吗?
最佳答案
我没有测试这个但是在 wordpress 目录的 inc/wp-phpass.php 中
function crypt_private($password, $setting)
{
$output = '*0';
if (substr($setting, 0, 2) == $output)
$output = '*1';
$id = substr($setting, 0, 3);
# We use "$P$", phpBB3 uses "$H$" for the same thing
if ($id != '$P$' && $id != '$H$')
return $output;
$count_log2 = strpos($this->itoa64, $setting[3]);
if ($count_log2 < 7 || $count_log2 > 30)
return $output;
$count = 1 << $count_log2;
$salt = substr($setting, 4, 8);
if (strlen($salt) != 8)
return $output;
# We're kind of forced to use MD5 here since it's the only
# cryptographic primitive available in all versions of PHP
# currently in use. To implement our own low-level crypto
# in PHP would result in much worse performance and
# consequently in lower iteration counts and hashes that are
# quicker to crack (by non-PHP code).
if (PHP_VERSION >= '5') {
$hash = md5($salt . $password, TRUE);
do {
$hash = md5($hash . $password, TRUE);
} while (--$count);
} else {
$hash = pack('H*', md5($salt . $password));
do {
$hash = pack('H*', md5($hash . $password));
} while (--$count);
}
$output = substr($setting, 0, 12);
$output .= $this->encode64($hash, 16);
return $output;
}
如您所见,他们确实使用简单的 md5 作为密码,您可以将其更改为您自己的逻辑,注意!!每次 WordPress 更新此文件时,您都必须手动更改此文件:/ 不是最好的解决方案,但我希望这对您有所帮助
关于php - 您如何将成员从另一个系统导入到 Wordpress 并更新密码以便它们可以工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31734557/