You are here

protected function TfaBasicRecoveryCode::validate in TFA Basic plugins 7

@copydoc TfaBasePlugin::validate()

Overrides TfaBasePlugin::validate

1 call to TfaBasicRecoveryCode::validate()
TfaBasicRecoveryCode::validateForm in includes/tfa_recovery.inc
@copydoc TfaBasePlugin::validateForm()

File

includes/tfa_recovery.inc, line 106
class for TFA Basic

Class

TfaBasicRecoveryCode
Class TfaBasicRecoveryCode

Code

protected function validate($code) {
  $this->isValid = FALSE;

  // Get codes and compare.
  $codes = $this
    ->getCodes();
  if (empty($codes)) {
    $this->errorMessages['code'] = t('You have no unused codes available.');
    return FALSE;
  }

  // Remove empty spaces.
  $code = str_replace(' ', '', $code);
  foreach ($codes as $id => $stored) {

    // Remove spaces from stored code.
    if (str_replace(' ', '', $stored) === $code) {
      $this->isValid = TRUE;
      $this->usedCode = $id;
      return $this->isValid;
    }
  }
  $this->errorMessages['code'] = t('Invalid recovery code.');
  return $this->isValid;
}