You are here

protected function GALoginHotpValidation::validate in Google Authenticator login 8

Validate code.

Note, plugins overriding validate() should be sure to set isValid property correctly or else also override submitForm().

Parameters

string $code: Code to be validated.

Return value

bool Whether code is valid.

Overrides TfaBasePlugin::validate

2 calls to GALoginHotpValidation::validate()
GALoginHotpValidation::validateForm in src/Plugin/TfaValidation/GALoginHotpValidation.php
Validate form.
GALoginHotpValidation::validateRequest in src/Plugin/TfaValidation/GALoginHotpValidation.php
Simple validate for web services.
1 method overrides GALoginHotpValidation::validate()
GALoginHotpSetup::validate in src/Plugin/TfaSetup/GALoginHotpSetup.php
Validate code.

File

src/Plugin/TfaValidation/GALoginHotpValidation.php, line 253

Class

GALoginHotpValidation
HOTP validation class for performing HOTP validation.

Namespace

Drupal\ga_login\Plugin\TfaValidation

Code

protected function validate($code) {

  // Strip whitespace.
  $code = preg_replace('/\\s+/', '', $code);
  if ($this
    ->alreadyAcceptedCode($code)) {
    $this->isValid = FALSE;
  }
  else {

    // Get OTP seed.
    $seed = $this
      ->getSeed();
    $counter = $this
      ->getHotpCounter();
    $this->isValid = $seed && ($counter = $this->auth->otp
      ->checkHotpResync(Encoding::base32DecodeUpper($seed), $counter, $code, $this->counterWindow));
    $this
      ->setUserData('tfa', [
      'tfa_hotp_counter' => ++$counter,
    ], $this->uid, $this->userData);
  }
  return $this->isValid;
}