You are here

protected function GALoginTotpValidation::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 GALoginTotpValidation::validate()
GALoginTotpValidation::validateForm in src/Plugin/TfaValidation/GALoginTotpValidation.php
Validate form.
GALoginTotpValidation::validateRequest in src/Plugin/TfaValidation/GALoginTotpValidation.php
Simple validate for web services.
1 method overrides GALoginTotpValidation::validate()
GALoginTotpSetup::validate in src/Plugin/TfaSetup/GALoginTotpSetup.php
Validate code.

File

src/Plugin/TfaValidation/GALoginTotpValidation.php, line 257

Class

GALoginTotpValidation
TOTP validation class for performing TOTP 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();
    $this->isValid = $seed && $this->auth->otp
      ->checkTotp(Encoding::base32DecodeUpper($seed), $code, $this->timeSkew);
  }
  return $this->isValid;
}