* For now im going to keep implementing it this way and thus my class will
* forever be an example of poor design choices. It'll change it very shortly though
*/
+
+/*
+ * The way we should really be doing things is to have an array that encapsulates "normal" data (or a class?)
+ * and then just manipulate it, then use a checkin function to push the data base into the db...
+ */
class GoogleAuthenticator {
// first we init google authenticator by passing it a filename
$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
return false;
}
- $put["username"] = $username;
- $put["tokentype"] = $tokentype;
+ $data = getData($username);
+ $data["tokentype"] = $tokentype;
$func = $this->putDataFunction;
$func("settokentype", $put);