コード例 #1
0
 /**
  * Verify a user token if it exists as part of the multi factor login process
  * 
  * Cyril Ogana <*****@*****.**> - 2016-07-05
  *
  * @return boolean
  * @throws UserCredentialException
  */
 protected function checkToken()
 {
     //instantiate MultiOtp Wrapper
     $multiOtpWrapper = new MultiotpWrapper();
     //get the username
     $currentUserName = $this->getCurrentUsername();
     //assert that username is set
     if (!\strlen((string) $currentUserName)) {
         throw new UserCredentialException('Cannot validate a TOTP token when username is not set!', 2106);
     }
     //assert that the token exists
     $tokenExists = $multiOtpWrapper->CheckTokenExists($currentUserName);
     if (!$tokenExists) {
         throw new UserCredentialException('The TOTP token for the current user does not exist', 2107);
     }
     //username mapped to their token name
     $multiOtpWrapper->setToken($currentUserName);
     //validate the Token
     $oneTimeToken = $this->getOneTimeToken();
     $tokenCheckResult = $multiOtpWrapper->CheckToken($oneTimeToken);
     //The results are reversed
     //TODO: Add intepretation of MultiOtp return results here to enable exception handling
     if ($tokenCheckResult == 0) {
         return true;
     } else {
         return false;
     }
 }
コード例 #2
0
 /**
  * Generate a 6 digit SMS token
  * Cyril Ogana <*****@*****.**>
  * 2015-07-24
  * 
  * @return string
  * 
  * @param string $userName - The username
  * @param string $keyString - String to use as a salt
  * 
  * @access public
  * @static
  */
 public static function generateToken($userName, $keyString)
 {
     $userNameCast = (string) $userName;
     $keyStringCast = (string) $keyString;
     $multiOtpObj = new MultiotpWrapper($keyStringCast);
     return $multiOtpObj->GenerateSmsToken($userNameCast);
 }