X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=blobdiff_plain;f=lib%2Fga4php.php;h=22a7b2c56a856ce7e91ee3a798c413e1c77dbd00;hp=2be25ff2828e56c460187e1281ad112004b616df;hb=HEAD;hpb=aca6e69a5eaa260bf6a7f676f31e43dd8e1e6158 diff --git a/lib/ga4php.php b/lib/ga4php.php index 2be25ff..22a7b2c 100644 --- a/lib/ga4php.php +++ b/lib/ga4php.php @@ -37,6 +37,20 @@ abstract class GoogleAuthenticator { return $data; } + // custom data field manipulation bits + function setCustomData($username, $data) { + $data = $this->internalGetData($username); + $data["user"] = $key; + $this->internalPutData($username, $data); + } + + function getCustomData($username) { + $data = $this->internalGetData($username); + $custom = $data["user"]; + return $custom; + + } + // an internal funciton to get data from the overloaded functions // and turn them into php arrays. function internalGetData($username) { @@ -53,7 +67,8 @@ abstract class GoogleAuthenticator { // the function used inside the class to put the data into the // datastore using the overloaded data saving class function internalPutData($username, $data) { - $enco = base64_encode(serialize($data)); + if($data == "") $enco = ""; + else $enco = base64_encode(serialize($data)); return $this->putData($username, $enco); } @@ -111,18 +126,21 @@ abstract class GoogleAuthenticator { // consider scrapping this $token = $this->internalGetData($username); $token["tokenkey"] = $key; - $this->internalPutData($username, $token); + $this->internalPutData($username, $token); + + // TODO error checking + return true; } // self explanitory? function deleteUser($username) { // oh, we need to figure out how to do thi? - $data = $this->internalGetData($username); - $data["tokenkey"] = ""; - $this->internalPutData($username); + $this->internalPutData($username, ""); } + + // user has input their user name and some code, authenticate // it function authenticateUser($username, $code) { @@ -148,11 +166,11 @@ abstract class GoogleAuthenticator { switch($ttype) { case "HOTP": error_log("in hotp"); - $st = $tlid; + $st = $tlid+1; $en = $tlid+$this->hotpSkew; for($i=$st; $i<$en; $i++) { $stest = $this->oath_hotp($tkey, $i); - error_log("testing code: $code, $stest, $tkey, $tid"); + //error_log("testing code: $code, $stest, $tkey, $tid"); if($code == $stest) { $tokendata["tokencounter"] = $i; $this->internalPutData($username, $tokendata); @@ -197,7 +215,7 @@ abstract class GoogleAuthenticator { // 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 = internalGetData($username); + $tokendata = $this->internalGetData($username); // TODO: check return value $ttype = $tokendata["tokentype"]; @@ -220,7 +238,7 @@ abstract class GoogleAuthenticator { $stest2 = $this->oath_hotp($tkey, $i+1); if($code2 == $stest2) { $tokendata["tokencounter"] = $i+1; - internalPutData($username, $tokendata); + $this->internalPutData($username, $tokendata); return true; } } @@ -248,7 +266,10 @@ abstract class GoogleAuthenticator { $data = $this->internalGetData($user); $toktype = $data["tokentype"]; $key = $this->helperhex2b32($data["tokenkey"]); - $counter = $data["tokencounter"]; + + // token counter should be one more then current token value, otherwise + // it gets confused + $counter = $data["tokencounter"]+1; $toktype = strtolower($toktype); if($toktype == "hotp") { $url = "otpauth://$toktype/$user?secret=$key&counter=$counter";