Automattic\WooCommerce\Internal\CustomerEmailVerification
EmailVerificationService::check_verification_key
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.
Method of the class: EmailVerificationService{}
No Hooks.
Returns
bool. True when the key is valid and has not expired.
Usage
$EmailVerificationService = new EmailVerificationService(); $EmailVerificationService->check_verification_key( $user_id, $key ): bool;
- $user_id(int) (required)
- WordPress user ID.
- $key(string) (required)
- The plaintext verification key to check.
Changelog
| Since 11.0.0 | Introduced. |
EmailVerificationService::check_verification_key() EmailVerificationService::check verification key code WC 11.0.1
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 );
}