X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=blobdiff_plain;f=lib%2Flib.php;h=01340d960df01c7b2533d61f6f824e8aaca83993;hp=262149f9cc2b2be20dd45071a01686f7a3dadfa2;hb=56b0dc03375e2a8facb8ff20c05d9be07dd6bcda;hpb=9b2752526f9f4bfac4831eb61fa63edd60117f77 diff --git a/lib/lib.php b/lib/lib.php index 262149f..01340d9 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -44,13 +44,15 @@ class GoogleAuthenticator { $sql = "select * from users where user_name='$username'"; $res = $this->dbConnector->query($sql); - if($res->fetchCount()>0) { - $this->errorText = "User Already Exists, $username"; - return false; - } + //if($res->fetchCount()>0) { + //$this->errorText = "User Already Exists, $username"; + //return false; + //} // and finally create 'em - $this->dbConnector->query("insert into tokens values (NULL, '$key', 'HOTP','0')"); + $hkey = $this->helperb322hex($key); + error_log("key for user $username is $hkey, $key"); + $this->dbConnector->query("insert into tokens values (NULL, '$hkey', 'HOTP','0')"); $id = $this->dbConnector->lastInsertID(); $this->dbConnector->query("insert into users values (NULL, '$username', '$id')"); @@ -95,7 +97,8 @@ class GoogleAuthenticator { //} // and finally create 'em - $this->dbConnector->query("insert into tokens values (NULL, '$key', 'HOTP', '0')"); + $hkey = $this->helperb322hex($key); + $this->dbConnector->query("insert into tokens values (NULL, '$hkey', 'HOTP', '0')"); $id = $this->dbConnector->lastInsertID(); $this->dbConnector->query("insert into users values (NULL, '$username', '$id')"); @@ -239,8 +242,8 @@ class GoogleAuthenticator { // create a url compatibile with google authenticator. function createURL($user, $key) { - $url = "otpauth://totp/$user?secret=$key"; - echo "url: $url\n"; + $url = "otpauth://hotp/$user?secret=$key"; + //echo "url: $url\n"; return $url; } @@ -329,7 +332,7 @@ class GoogleAuthenticator { // HMAC $hash = hash_hmac ('sha1', $bin_counter, $key); - return $this->oath_truncate($hash); + return str_pad($this->oath_truncate($hash), 6, "0", STR_PAD_LEFT); } function oath_truncate($hash, $length = 6)