WordPress使用自带方法生成密文和验证密码

2019-03-1021:01:21网站建设与开发Comments2,376 views字数 1014阅读模式

WordPress使用自带方法生成密文和验证密码文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/9903.html

WordPress中主要用到两个函数wp_hash_password() 和 wp_check_password()来对文本进行生成密文和对密文的验证。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/9903.html

wp_hash_password() 把一个文本生成加密密文。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/9903.html

  1. function wp_hash_password($password) {
  2.     global $wp_hasher;
  3.     if ( emptyempty($wp_hasher) ) {
  4.         require_once( ABSPATH . WPINC . '/class-phpass.php');
  5.         // By default, use the portable hash from phpass
  6.         $wp_hasher = new PasswordHash(8, true);
  7.     }
  8.     return $wp_hasher->HashPassword( trim( $password ) );
  9. }

wp_check_password() 通过把生成的密文和文本密码进行比对来验证密码。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/9903.html

  1. function wp_check_password($password$hash$user_id = '') {
  2.     global $wp_hasher;
  3.     if ( emptyempty($wp_hasher) ) {
  4.         require_once( ABSPATH . WPINC . '/class-phpass.php');
  5.         // By default, use the portable hash from phpass
  6.         $wp_hasher = new PasswordHash(8, true);
  7.     }
  8.     $check = $wp_hasher->CheckPassword($password$hash);
  9.     return apply_filters( 'check_password', $check$password$hash$user_id );
  10. }

简易的使用方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/9903.html

  1. //生成加密密文
  2. $password = wp_hash_password("qcqx");
  3. //把密文和文本验证
  4. echo wp_check_password("qcqx",$password ) ;
  5. //输出 1,对比成功
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/9903.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/9903.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定