You are here

public function GoogleAuthenticator::resyncCode in Google Authenticator login 7

Same name and namespace in other branches
  1. 6 ga4php.php \GoogleAuthenticator::resyncCode()

Resync codes.

File

./ga4php.php, line 232
Abstract GoogleAuthenticator class.

Class

GoogleAuthenticator
@file Abstract GoogleAuthenticator class.

Code

public function resyncCode($username, $code1, $code2) {
  $tokendata = $this
    ->internalGetData($username);

  // @todo check return value.
  $ttype = $tokendata["tokentype"];
  $tlid = $tokendata["tokencounter"];
  $tkey = $tokendata["tokenkey"];
  if ($tkey == "") {
    $this->errorText = "No Assigned Token";
    return FALSE;
  }
  switch ($ttype) {
    case "HOTP":
      $st = 0;
      $en = $this->hotpHuntValue;
      for ($i = $st; $i < $en; $i++) {
        $stest = $this
          ->oathHotp($tkey, $i);
        if ($code1 == $stest) {
          $stest2 = $this
            ->oathHotp($tkey, $i + 1);
          if ($code2 == $stest2) {
            $tokendata["tokencounter"] = $i + 1;
            $this
              ->internalPutData($username, $tokendata);
            return TRUE;
          }
        }
      }
      return FALSE;
    case "TOTP":
      break;
    default:
      echo "how the frig did i end up here?";
  }
  return FALSE;
}