wp_password_needs_rehash()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_password_needs_rehash( string $hash, string|int $user_id = '' ): bool
Описание
Пароли хешируются с помощью bcrypt со стоимостью по умолчанию. Пароль, хешированный в предыдущей версии WordPress, может по-прежнему быть хеширован с помощью phpass, и его потребуется хешировать заново. Если стоимость или алгоритм по умолчанию изменяются в PHP или WordPress, то пароль, хешированный в предыдущей версии, потребуется хешировать заново.
Обратите внимание, что, как и wp_check_password() , эта функция может использоваться для проверки значения, не являющегося паролем пользователя. Плагин может использовать её для проверки пароля другого типа, и с паролем не всегда может быть связан ID пользователя.
Оригинал (английский)
Passwords are hashed with bcrypt using the default cost. A password hashed in a prior version of WordPress may still be hashed with phpass and will need to be rehashed. If the default cost or algorithm is changed in PHP or WordPress then a password hashed in a previous version will need to be rehashed.
Note that, just like wp_check_password() , this function may be used to check a value that is not a user password. A plugin may use this function to check a password of a different type, and there may not always be a user ID associated with the password.
Параметры
$hash
string
обязательный
$user_id
string|int
необязательный
= ''
Возвращаемое значение
bool
Исходный код
wp-includes/pluggable.php:2907
function wp_password_needs_rehash( $hash, $user_id = '' ) {
global $wp_hasher;
if ( ! empty( $wp_hasher ) ) {
return false;
}
/** This filter is documented in wp-includes/pluggable.php */
$algorithm = apply_filters( 'wp_hash_password_algorithm', PASSWORD_BCRYPT );
/** This filter is documented in wp-includes/pluggable.php */
$options = apply_filters( 'wp_hash_password_options', array(), $algorithm );
$prefixed = str_starts_with( $hash, '$wp' );
if ( ( PASSWORD_BCRYPT === $algorithm ) && ! $prefixed ) {
// If bcrypt is in use and the hash is not prefixed then it needs to be rehashed.
$needs_rehash = true;
} else {
// Otherwise check the hash minus its prefix if necessary.
$hash_to_check = $prefixed ? substr( $hash, 3 ) : $hash;
$needs_rehash = password_needs_rehash( $hash_to_check, $algorithm, $options );
}
/**
* Filters whether the password hash needs to be rehashed.
*
* @since 6.8.0
*
* @param bool $needs_rehash Whether the password hash needs to be rehashed.
* @param string $hash The password hash.
* @param string|int $user_id Optional. ID of a user associated with the password.
*/
return apply_filters( 'password_needs_rehash', $needs_rehash, $hash, $user_id );
}
История изменений
| Версия | Описание |
|---|---|
| 6.8.0 | Introduced. |

