class GALoginGA in Google Authenticator login 7
Hierarchy
- class \GoogleAuthenticator
- class \GALoginGA
Expanded class hierarchy of GALoginGA
File
- ./
ga_login.class.php, line 12
View source
class GALoginGA extends GoogleAuthenticator {
/**
* Load data associated with a user.
*/
public function getData($username) {
$result = db_select('ga_login')
->fields('ga_login', array(
'keydata',
))
->condition('name', $username)
->execute()
->fetchAssoc();
// Check the result.
if (!$result) {
return FALSE;
}
// Decrypt the data, if a plugin in available.
if (module_exists('aes')) {
return aes_decrypt($result["keydata"]);
}
elseif (module_exists('encrypt')) {
return decrypt($result["keydata"]);
}
return $result["keydata"];
}
/**
* Save data associated with a user.
*/
public function putData($username, $data) {
// Encrypt the data, if a plugin in available.
if (module_exists('aes')) {
$data = aes_encrypt($data);
}
elseif (module_exists('encrypt')) {
$data = encrypt($data);
}
$result = db_merge('ga_login')
->key(array(
'name' => $username,
))
->fields(array(
'keydata' => $data,
))
->execute();
if ($result) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* Not used.
*/
public function getUsers() {
// Abstract function from base class.
}
/**
* Create empty data.
*/
public function createEmptyData() {
$data = parent::createEmptyData();
$data["tokentype"] = "TOTP";
return $data;
}
/**
* Create "user" withOUT insert.
*/
public function unapprovedUser($username, $ttype = "HOTP", $key = "", $hexkey = "") {
$ttype = strtoupper($ttype);
if ($ttype != "HOTP" && $ttype != "TOTP") {
return FALSE;
}
if ($hexkey != "") {
$hkey = $hexkey;
}
else {
if ($key == "") {
$key = $this
->createBase32Key();
}
$hkey = $this
->helperb322hex($key);
}
$token = $this
->internalGetData($username);
$token["tokenkey"] = $hkey;
$token["tokentype"] = $ttype;
return $token;
}
/**
* Create authentication URL.
*/
public function createURL($user, $data = NULL) {
if (is_null($data)) {
return parent::createURL($user);
}
else {
$toktype = $data["tokentype"];
$key = $this
->helperhex2b32($data["tokenkey"]);
// Token counter should be one more then current token value,
// otherwise it gets confused.
$counter = $data["tokencounter"] + 1;
$toktype = strtolower($toktype);
if ($toktype == "hotp") {
$url = "otpauth://{$toktype}/{$user}?secret={$key}&counter={$counter}";
}
else {
$url = "otpauth://{$toktype}/{$user}?secret={$key}";
}
return $url;
}
}
/**
* Authenticate a user.
*/
public function authenticateUser($username, $code, $tokendata = FALSE) {
if (preg_match("/[0-9][0-9][0-9][0-9][0-9][0-9]/", $code) < 1) {
$this->errorText = "6 digits please";
return FALSE;
}
if ($username && !$tokendata) {
$tokendata = $this
->internalGetData($username);
}
if ($tokendata["tokenkey"] == "") {
$this->errorText = "No Assigned Token";
return FALSE;
}
$ttype = $tokendata["tokentype"];
$tlid = $tokendata["tokencounter"];
$tkey = $tokendata["tokenkey"];
switch ($ttype) {
case "HOTP":
$st = $tlid + 1;
$en = $tlid + $this->hotpSkew;
for ($i = $st; $i < $en; $i++) {
$stest = $this
->oathHotp($tkey, $i);
if ($code == $stest) {
$tokendata["tokencounter"] = $i;
$this
->internalPutData($username, $tokendata);
return TRUE;
}
}
return FALSE;
case "TOTP":
$t_now = REQUEST_TIME;
$t_ear = $t_now - $this->totpSkew * $tokendata["tokentimer"];
$t_lat = $t_now + $this->totpSkew * $tokendata["tokentimer"];
$t_st = (int) ($t_ear / $tokendata["tokentimer"]);
$t_en = (int) ($t_lat / $tokendata["tokentimer"]);
// Make sure we only check against newer codes.
if (isset($tokendata["tokencounter"]) && $tokendata["tokencounter"] >= $t_st) {
$t_st = $tokendata["tokencounter"] + 1;
}
for ($i = $t_st; $i <= $t_en; $i++) {
$stest = $this
->oathHotp($tkey, $i);
if ($code == $stest) {
$tokendata["tokencounter"] = $i;
$this
->internalPutData($username, $tokendata);
return TRUE;
}
}
break;
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GALoginGA:: |
public | function |
Authenticate a user. Overrides GoogleAuthenticator:: |
|
GALoginGA:: |
public | function |
Create empty data. Overrides GoogleAuthenticator:: |
|
GALoginGA:: |
public | function |
Create authentication URL. Overrides GoogleAuthenticator:: |
|
GALoginGA:: |
public | function |
Load data associated with a user. Overrides GoogleAuthenticator:: |
|
GALoginGA:: |
public | function |
Not used. Overrides GoogleAuthenticator:: |
|
GALoginGA:: |
public | function |
Save data associated with a user. Overrides GoogleAuthenticator:: |
|
GALoginGA:: |
public | function | Create "user" withOUT insert. | |
GoogleAuthenticator:: |
private | property | ||
GoogleAuthenticator:: |
private | property | ||
GoogleAuthenticator:: |
private | property | ||
GoogleAuthenticator:: |
protected | property | ||
GoogleAuthenticator:: |
protected | property | ||
GoogleAuthenticator:: |
private | property | ||
GoogleAuthenticator:: |
protected | property | ||
GoogleAuthenticator:: |
public | function | Creates a base 32 key (random). | |
GoogleAuthenticator:: |
public | function | Delete a user. | |
GoogleAuthenticator:: |
public | function | Load custom data. | |
GoogleAuthenticator:: |
public | function | Gets the error text associated with the last error. | |
GoogleAuthenticator:: |
public | function | Get hex key. | |
GoogleAuthenticator:: |
public | function | Get token type. | |
GoogleAuthenticator:: |
public | function | Determine if the user has an actual token. | |
GoogleAuthenticator:: |
public | function | Convert b32 to hex. | |
GoogleAuthenticator:: |
public | function | Convert hax to b32. | |
GoogleAuthenticator:: |
public | function | Load internal data. | |
GoogleAuthenticator:: |
public | function | Store data. | |
GoogleAuthenticator:: |
public | function | Create HOTP. | |
GoogleAuthenticator:: |
public | function | Truncate. | |
GoogleAuthenticator:: |
public | function | Resync codes. | |
GoogleAuthenticator:: |
public | function | Set custom data. | |
GoogleAuthenticator:: |
public | function | Sets the token type the user it going to use. | |
GoogleAuthenticator:: |
public | function | Create a user. | |
GoogleAuthenticator:: |
public | function | Sets a users key. | |
GoogleAuthenticator:: |
public | function | Constructor. |