You are here

function GoogleAuthenticator::setUser in Google Authenticator login 6

Same name and namespace in other branches
  1. 7 ga4php.php \GoogleAuthenticator::setUser()

File

./ga4php.php, line 101

Class

GoogleAuthenticator

Code

function setUser($username, $ttype = "HOTP", $key = "", $hexkey = "") {
  $ttype = strtoupper($ttype);
  if ($ttype != "HOTP" && $ttype != "TOTP") {
    return false;
  }
  if ($key == "") {
    $key = $this
      ->createBase32Key();
  }
  $hkey = $this
    ->helperb322hex($key);
  if ($hexkey != "") {
    $hkey = $hexkey;
  }
  $token = $this
    ->internalGetData($username);
  $token["tokenkey"] = $hkey;
  $token["tokentype"] = $ttype;
  if (!$this
    ->internalPutData($username, $token)) {
    return false;
  }
  return $key;
}