# check_password_reset_key()

URL: https://chugunov.pro/api-wordpress/functions/check_password_reset_key/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 3.1.0.

## Сигнатура

```php
check_password_reset_key( string $key, string $login ): WP_User|WP_Error
```

## Описание

Ключ считается 'истёкшим', если он в точности совпадает со значением поля user_activation_key, а не при совпадении после прохождения через хеширование. Теперь это поле хешируется; старые значения больше не принимаются, но имеют другой код WP_Error, что позволяет предоставить пользователю понятную обратную связь.

## Параметры

- `$key` `string` — обязательный. Ключ сброса пароля.
- `$login` `string` — обязательный. Логин пользователя.

## Возвращаемое значение

`WP_User|WP_Error` — WP_User WP_Error

## Исходный код

Файл: `wp-includes/user.php:3157`

```php
function check_password_reset_key(
	#[\SensitiveParameter]
	$key,
	$login
) {
	$key = preg_replace( '/[^a-z0-9]/i', '', $key );

	if ( empty( $key ) || ! is_string( $key ) ) {
		return new WP_Error( 'invalid_key', __( 'Invalid key.' ) );
	}

	if ( empty( $login ) || ! is_string( $login ) ) {
		return new WP_Error( 'invalid_key', __( 'Invalid key.' ) );
	}

	$user = get_user_by( 'login', $login );

	if ( ! $user ) {
		return new WP_Error( 'invalid_key', __( 'Invalid key.' ) );
	}

	/**
	 * Filters the expiration time of password reset keys.
	 *
	 * @since 4.3.0
	 *
	 * @param int $expiration The expiration time in seconds.
	 */
	$expiration_duration = apply_filters( 'password_reset_expiration', DAY_IN_SECONDS );

	if ( str_contains( $user->user_activation_key, ':' ) ) {
		list( $pass_request_time, $pass_key ) = explode( ':', $user->user_activation_key, 2 );
		$expiration_time                      = $pass_request_time + $expiration_duration;
	} else {
		$pass_key        = $user->user_activation_key;
		$expiration_time = false;
	}

	if ( ! $pass_key ) {
		return new WP_Error( 'invalid_key', __( 'Invalid key.' ) );
	}

	$hash_is_correct = wp_verify_fast_hash( $key, $pass_key );

	if ( $hash_is_correct && $expiration_time && time() < $expiration_time ) {
		return $user;
	} elseif ( $hash_is_correct && $expiration_time ) {
		// Key has an expiration time that's passed.
		return new WP_Error( 'expired_key', __( 'Invalid key.' ) );
	}

	if ( hash_equals( $user->user_activation_key, $key ) || ( $hash_is_correct && ! $expiration_time ) ) {
		$return  = new WP_Error( 'expired_key', __( 'Invalid key.' ) );
		$user_id = $user->ID;

		/**
		 * Filters the return value of check_password_reset_key() when an
		 * old-style key or an expired key is used.
		 *
		 * Prior to 3.7, plain-text keys were stored in the database.
		 *
		 * @since 3.7.0
		 * @since 4.3.0 Previously key hashes were stored without an expiration time.
		 *
		 * @param WP_Error $return  A WP_Error object denoting an expired key.
		 *                          Return a WP_User object to validate the key.
		 * @param int      $user_id The matched user ID.
		 */
		return apply_filters( 'password_reset_key_expired', $return, $user_id );
	}

	return new WP_Error( 'invalid_key', __( 'Invalid key.' ) );
}
```

## История изменений

- 3.1.0 — Introduced.

## Связанные

Использует: [`wp_verify_fast_hash`](https://chugunov.pro/api-wordpress/functions/wp_verify_fast_hash/), [`wp_fast_hash`](https://chugunov.pro/api-wordpress/functions/wp_fast_hash/), [`get_user_by`](https://chugunov.pro/api-wordpress/functions/get_user_by/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), `WP_Error::__construct`.

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/check_password_reset_key/
