// create "user" with insert
- function setUser($username, $key = "", $ttype="HOTP") {
+ function setUser($username, $ttype="HOTP", $key = "") {
if($key == "") $key = $this->createBase32Key();
$hkey = $this->helperb322hex($key);
// TODO: change this to a pattern match for an actual key
if(!isset($token["tokenkey"])) return false;
if($token["tokenkey"] == "") return false;
+ return true;
}
error_log("dat is $asdf");
switch($ttype) {
case "HOTP":
+ error_log("in hotp");
$st = $tlid;
$en = $tlid+20;
for($i=$st; $i<$en; $i++) {
$stest = $this->oath_hotp($tkey, $i);
- //error_log("code: $code, $stest, $tkey, $tid");
+ error_log("testing code: $code, $stest, $tkey, $tid");
if($code == $stest) {
$tokendata["tokencounter"] = $i;
$this->internalPutData($username, $tokendata);
return false;
break;
case "TOTP":
+ error_log("in totp");
$t_now = time();
$t_ear = $t_now - 45;
$t_lat = $t_now + 60;
//error_log("kmac: $t_now, $t_ear, $t_lat, $t_st, $t_en");
for($i=$t_st; $i<=$t_en; $i++) {
$stest = $this->oath_hotp($tkey, $i);
- //error_log("code: $code, $stest, $tkey\n");
+ error_log("testing code: $code, $stest, $tkey\n");
if($code == $stest) {
return true;
}
// oddity in the google authenticator... hotp needs to be lowercase.
$data = $this->internalGetData($user);
$toktype = $data["tokentype"];
- $key = $data["tokenkey"];
+ $key = $this->helperhex2b32($data["tokenkey"]);
$toktype = strtolower($toktype);
if($toktype == "hotp") {
$url = "otpauth://$toktype/$user?secret=$key&counter=1";
return $key;
}
+
+ // returns a hex key
+ function getKey($username) {
+ $data = $this->internalGetData($username);
+ $key = $data["tokenkey"];
+
+ return $key;
+ }
+
+ // get key type
+ function getTokenType($username) {
+ $data = $this->internalGetData($username);
+ $toktype = $data["tokentype"];
+ return $toktype;
+ }
+
function helperb322hex($b32) {
$alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";