function GoogleAuthenticator::resyncCode in Google Authenticator login 6
Same name and namespace in other branches
- 7 ga4php.php \GoogleAuthenticator::resyncCode()
File
- ./
ga4php.php, line 217
Class
Code
function resyncCode($username, $code1, $code2) {
// here we'll go from 0 all the way thru to 200k.. if we cant find the code, so be it, they'll need a new one
// for HOTP tokens we start at x and go to x+20
// for TOTP we go +/-1min TODO = remember that +/- 1min should
// be changed based on stepping if we change the expiration time
// for keys
// $this->dbConnector->query('CREATE TABLE "tokens" ("token_id" INTEGER PRIMARY KEY AUTOINCREMENT,"token_key" TEXT NOT NULL, "token_type" TEXT NOT NULL, "token_lastid" INTEGER NOT NULL)');
$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
->oath_hotp($tkey, $i);
//echo "code: $code, $stest, $tkey\n";
if ($code1 == $stest) {
$stest2 = $this
->oath_hotp($tkey, $i + 1);
if ($code2 == $stest2) {
$tokendata["tokencounter"] = $i + 1;
$this
->internalPutData($username, $tokendata);
return true;
}
}
}
return false;
break;
case "TOTP":
// ignore it?
break;
default:
echo "how the frig did i end up here?";
}
return false;
}