WordPress 中是如何加密和验证密码的

在 WordPress 中是如何加密和验证用户的密码的呢?WordPress 主要使用了两个函数:wp_hash_password()wp_check_password()

wp_hash_password($password) 把一个纯文本加密成密文。

function wp_hash_password( $password ) {
global $wp_hasher;
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 );
}
return $wp_hasher->HashPassword( trim( $password ) );
}

wp_check_password($password, $hash, $user_id = '') 把纯文本和密文进行比对来验证密码。

function wp_check_password( $password, $hash, $user_id = '' ) {
global $wp_hasher;
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 );
}

从上面的代码可以看出,WordPress 是使用一个 phpass(全称是:Portable PHP password hashing framework)开源的类生成和验证密码的。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容