X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=blobdiff_plain;f=lib%2Flib.php;fp=lib%2Flib.php;h=42bc5991cdcc467afc96435d11d340643178efa3;hp=169b9a8d6f6257625fee86ca4fa07abfc1fa01b6;hb=98a6dee8498b3472e6f8fa9989279dddf4b1eefa;hpb=a766aae1ec9ecafa3f1e0b8452df71e92d109cba diff --git a/lib/lib.php b/lib/lib.php index 169b9a8..42bc599 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -44,12 +44,41 @@ class GoogleAuthenticator { $this->getDataFunction = $getDataFunction; } - // this could get ugly for large databases.. we'll worry about that if it ever happens. - function getUserList() { - $func = $this->getDataFunction; - return $func("userlist", ""); + abstract function getData($username); + abstract function putData($username, $data); + abstract function getUsers(); + + // a function to create an empty data structure + function createEmptyData() { + $data["tokenkey"] = ""; // the token key + $data["tokentype"] = ""; // the token type + $data["tokentimer"] = ""; // the token timer (For totp) and not supported by ga yet + $data["tokencounter"] = ""; // the token counter for hotp + $data["tokenalgorithm"] = ""; // the token algorithm (not supported by ga yet) + + return $data; } + // an internal funciton to get + function internalGetData($username) { + $data = getData($username); + $deco = unserialize(base64_decode($data)); + + if(!$deco) { + $deco = createEmptyData(); + } + + return $deco; + } + + + function internalPutData($username, $data) { + $enco = base64_encode(serialize($data)); + + return putData($username, $enco); + } + + // set the token type the user it going to use. // this defaults to HOTP - we only do 30s token // so lets not be able to set that yet @@ -59,8 +88,8 @@ class GoogleAuthenticator { return false; } - $put["username"] = $username; - $put["tokentype"] = $tokentype; + $data = getData($username); + $data["tokentype"] = $tokentype; $func = $this->putDataFunction; $func("settokentype", $put);