From 98a6dee8498b3472e6f8fa9989279dddf4b1eefa Mon Sep 17 00:00:00 2001 From: paulr Date: Tue, 16 Nov 2010 16:04:23 +1100 Subject: [PATCH] moving to an overload function --- doco/datafunctions.txt | 3 +++ doco/datastructure.txt | 5 +++++ doco/readme.txt | 1 + lib/lib.php | 41 +++++++++++++++++++++++++++++++++++------ 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 doco/datastructure.txt diff --git a/doco/datafunctions.txt b/doco/datafunctions.txt index 2ee267e..c85226a 100644 --- a/doco/datafunctions.txt +++ b/doco/datafunctions.txt @@ -1,3 +1,6 @@ +DEPRECATED INFO - IGNORE THIS! + + Put data Functions: Token type: diff --git a/doco/datastructure.txt b/doco/datastructure.txt new file mode 100644 index 0000000..6ba590b --- /dev/null +++ b/doco/datastructure.txt @@ -0,0 +1,5 @@ +$data["tokenkey"] = "...."; // the token key +$data["tokentype"] = "...."; // the token type +$data["tokencounter"] = "...."; // the token counter for hotp +$data["tokenalgorithm"] = "...."; // the token algorithm (not supported by ga yet) +$data["tokentimer"] = "...." // the token timer (For totp) and not supported by ga yet diff --git a/doco/readme.txt b/doco/readme.txt index 9067210..8c8c9a8 100644 --- a/doco/readme.txt +++ b/doco/readme.txt @@ -50,6 +50,7 @@ Usage ===== ... TODO ... + Complications ============= 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); -- 1.7.0.4