wp_check_password

函数


wp_check_password ( $password, $hash, $user_id = '' )
参数
  • (string)
    $password
    Plaintext user’s password.
    Required:
  • (string)
    $hash
    Hash of the user’s password to check against.
    Required:
  • (string|int)
    $user_id
    Optional. User ID.
    Required:
    Default: (empty)
返回值
  • (bool) False, if the $password does not match the hashed password.
定义位置
  • wp-includes/pluggable.php
    , line 2535
引入
2.5.0
弃用

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.

function wp_check_password( $password, $hash, $user_id = '' ) {
		global $wp_hasher;

		// If the hash is still md5...
		if ( strlen( $hash ) CheckPassword( $password, $hash );

		/** This filter is documented in wp-includes/pluggable.php */
		return apply_filters( 'check_password', $check, $password, $hash, $user_id );
	}
endif;

if ( ! function_exists( 'wp_generate_password' ) ) :
	/**
	 * Generates a random password drawn from the defined set of characters.
	 *
	 * Uses wp_rand() is used to create passwords with far less predictability
	 * than similar native PHP functions like `rand()` or `mt_rand()`.
	 *
	 * @since 2.5.0
	 *
	 * @param int  $length              Optional. The length of password to generate. Default 12.
	 * @param bool $special_chars       Optional. Whether to include standard special characters.
	 *                                  Default true.
	 * @param bool $extra_special_chars Optional. Whether to include other special characters.
	 *                                  Used when generating secret keys and salts. Default false.
	 * @return string The random password.
	 */