Example #1
0
 /**
  * Check if a totp corresponds to a key and a stamp.
  *
  * @param string $key
  * @param int    $totp
  *
  * @return bool Return true if the totp corresponds to the key and the stamp provided
  */
 public function validate($totp, $key, $stamp = null)
 {
     if ($stamp === null) {
         $stamp = $this->timeManager->getCurrentStamp();
     }
     if (!preg_match('/^[0-9]{6}$/', $totp)) {
         return false;
     }
     $totp = intval($totp);
     // Search the stamp corresponding to the totp provided
     for ($st = $stamp - $this->window; $st <= $stamp + $this->window; ++$st) {
         if (($res = TOTPGenerator::generate($st, $key)) == $totp) {
             return $st;
         }
     }
     return false;
 }
Example #2
0
 /**
  * Alias of {@link TOTPGenerator::generate()}.
  */
 public static function generateTOTP($stamp, $key)
 {
     return TOTPGenerator::generate($stamp, $key);
 }