发布时间:2020-09-17
WordPress 是如何生成和验证密码的,
WordPress 中是如何生成和验证用户的密码的呢?WordPress 主要使用了两个函数:wp_hash_password()
和 wp_check_password()
:
wp_hash_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()
把纯文本和密文进行比对来验证密码。
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>
function wp_check_password($password, $hash, $user_id = '') {
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);
}
$check = $wp_hasher->CheckPassword($password, $hash);
return apply_filters( 'check_password', $check, $password, $hash, $user_id );
}
从上面的代码可以看出,WordPress 是使用一个 (全称是:Portable PHP password hashing framework)开源的类生成和验证密码的。
本站推荐使用的主机:,国外主机建议使用。
全站搜索