wp_hash_password

函数
wp_hash_password ( $password )
参数
  • (string) $password Plain text user password to hash.
    Required:
返回值
  • (string) The hash string of the password.
定义位置
相关方法
wp_set_passwordwp_check_passwordwp_generate_passwordwp_lostpassword_urlreset_password
引入
2.5.0
弃用
-

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 ) );
	}
endif;

if ( ! function_exists( 'wp_check_password' ) ) :
	/**
	 * Checks the plaintext password against the encrypted Password.
	 *
	 * Maintains compatibility between old version and the new cookie authentication
	 * protocol using PHPass library. The $hash parameter is the encrypted password
	 * and the function compares the plain text password when encrypted similarly
	 * against the already encrypted password to see if they match.
	 *
	 * For integration with other applications, this function can be overwritten to
	 * instead use the other package password checking algorithm.
	 *
	 * @since 2.5.0
	 *
	 * @global PasswordHash $wp_hasher PHPass object used for checking the password
	 *                                 against the $hash + $password.
	 * @uses PasswordHash::CheckPassword
	 *
	 * @param string     $password Plaintext user's password.
	 * @param string     $hash     Hash of the user's password to check against.
	 * @param string|int $user_id  Optional. User ID.
	 * @return bool False, if the $password does not match the hashed password.
	 */

常见问题

FAQs
查看更多 >