X-Git-Url: http://git.pjr.cc/?a=blobdiff_plain;f=authserver%2Flib%2Flib.php;h=9737566cc96daa7a61c48440bc526b2fd0b7566c;hb=34cbcba6d0f7c0a92c849545712cc5ce7ec03f97;hp=cf4c39e43dc923c13764a3f8185fe5d5865ec7b0;hpb=d1eae3d523f459b4cdd5e1bfc776690d0ad96069;p=ga4php.git diff --git a/authserver/lib/lib.php b/authserver/lib/lib.php index cf4c39e..9737566 100644 --- a/authserver/lib/lib.php +++ b/authserver/lib/lib.php @@ -11,10 +11,27 @@ define("MSG_AUTH_USER_PASSWORD", 4); define("MSG_SET_USER_PASSWORD", 5); define("MSG_SET_USER_REALNAME", 6); define("MSG_SET_USER_TOKEN", 7); +define("MSG_SET_USER_TOKEN_TYPE", 8); +define("MSG_GET_USERS", 9); +define("MSG_GET_OTK_PNG", 10); if(file_exists("../../lib/ga4php.php")) require_once("../../lib/ga4php.php"); if(file_exists("../lib/ga4php.php")) require_once("../lib/ga4php.php"); + +function generateRandomString() +{ + $str = ""; + $strpos = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + + for($i=0; $i<128; $i++) { + $str .= $strpos[rand(0, strlen($strpos)-1)]; + } + + return $str; +} + + function getDatabase() { $dbobject = false; if(file_exists("gaasdata.sqlite")) { @@ -29,7 +46,7 @@ function getDatabase() { } catch(PDOException $exep) { error_log("execpt on db open"); } - $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT, "users_realname" TEXT, "users_password" TEXT, "users_tokendata" TEXT);'; + $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT, "users_realname" TEXT, "users_password" TEXT, "users_tokendata" TEXT, "users_otk" TEXT);'; $dbobject->query($sql); } @@ -42,6 +59,7 @@ function closeDatabase($db) { class gaasGA extends GoogleAuthenticator { function getData($username) { + echo "called into getdata\n"; // get our database connection $dbObject = getDatabase(); @@ -53,14 +71,17 @@ class gaasGA extends GoogleAuthenticator { $result = $dbObject->query($sql); // check the result + echo "next1\n"; if(!$result) return false; // now just retreieve all the data (there should only be one, but whatever) + echo "next2\n"; $tokendata = false; foreach($result as $row) { $tokendata = $row["users_tokendata"]; } - + + echo "next3, $username, $tokendata\n"; // now we have our data, we just return it. If we got no data // we'll just return false by default return $tokendata; @@ -75,13 +96,13 @@ class gaasGA extends GoogleAuthenticator { // we need to check if the user exists, and if so put the data, if not create the data $sql = "select * from users where users_username='$username'"; - $res = $dbOject->query($sql); + $res = $dbObject->query($sql); if($res->fetchColumn() > 0) { // do update $sql = "update users set users_tokendata='$data' where users_username='$username'"; } else { // do insert - $sql = "insert into users values (NULL, '$username', '', '', '$data')"; + $sql = "insert into users values (NULL, '$username', '', '', '$data', '')"; } if($dbObject->query($sql)) { @@ -116,4 +137,4 @@ class gaasGA extends GoogleAuthenticator { } } -?> \ No newline at end of file +?>