Airship\Cabin\Bridge\Blueprint\UserAccounts::getTwoFactorSecret PHP Method

getTwoFactorSecret() public method

Get the user's two-factor authentication secret
public getTwoFactorSecret ( integer $userID ) : string
$userID integer
return string
    public function getTwoFactorSecret(int $userID) : string
    {
        $secret = $this->db->cell('SELECT totp_secret FROM airship_users WHERE userid = ?', $userID);
        if (empty($secret)) {
            return '';
        }
        $state = State::instance();
        return Symmetric::decrypt($secret, $state->keyring['auth.password_key']);
    }

Usage Example

Esempio n. 1
0
 /**
  * Make sure the secret exists, then get the GoogleAuth object
  *
  * @param int $userID
  * @return GoogleAuth
  * @throws \Airship\Alerts\Security\UserNotLoggedIn
  */
 protected function twoFactorPreamble(int $userID = 0) : GoogleAuth
 {
     if (!$userID) {
         $userID = $this->getActiveUserId();
     }
     $secret = $this->acct->getTwoFactorSecret($userID);
     if (empty($secret)) {
         if (!$this->acct->resetTwoFactorSecret($userID)) {
             \Airship\json_response(['test2']);
             \Airship\redirect($this->airship_cabin_prefix);
         }
         $secret = $this->acct->getTwoFactorSecret($userID);
     }
     return new GoogleAuth($secret, new TOTP(0, (int) ($this->config('two-factor.period') ?? 30), (int) ($this->config('two-factor.length') ?? 6)));
 }