Automattic\WooCommerce\Internal\CustomerEmailVerification

EmailVerificationService::check_verification_key │ public │ WC 11.0.0

Validate a plaintext verification key against the stored hash for the given user.

Returns false if no key is stored, if the key has expired, if the account email has changed since the key was issued, or if the key does not match the stored hash.

Метод класса: EmailVerificationService{}

Хуков нет.

Возвращает

bool. True when the key is valid and has not expired.

Использование

$EmailVerificationService = new EmailVerificationService();
$EmailVerificationService->check_verification_key( $user_id, $key ): bool;
$user_id(int) (обязательный)
WordPress user ID.
$key(строка) (обязательный)
The plaintext verification key to check.

Список изменений

С версии 11.0.0 Введена.

Код EmailVerificationService::check_verification_key() WC 11.2.2

public function check_verification_key( int $user_id, string $key ): bool {
	if ( '' === $key ) {
		return false;
	}

	$parsed = $this->parse_stored_key( $user_id );

	if ( null === $parsed ) {
		return false;
	}

	list( $timestamp, $hash, $email_hash ) = $parsed;

	if ( time() - $timestamp > self::KEY_TTL ) {
		return false;
	}

	// The key is void if the account email no longer matches the one it was minted for.
	$account_email = $this->get_account_email( $user_id );

	if ( null === $account_email || '' === $email_hash || ! wp_verify_fast_hash( $account_email, $email_hash ) ) {
		return false;
	}

	return wp_verify_fast_hash( $key, $hash );
}