Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function validate($otp, $counter = null)
 {
     if ($counter === null) {
         $counter = time();
     }
     $window = $this->getWindow();
     $counter = self::timestampToCounter($counter, $this->getTimeStep());
     $valid = false;
     $offset = null;
     $counterLow = max(0, $counter - intval(floor($window / 2)));
     $counterHigh = max(0, $counter + intval(ceil($window / 2)));
     for ($current = $counterLow; $current <= $counterHigh; ++$current) {
         if ($otp === parent::calculate($current)) {
             $valid = true;
             $offset = $current - $counter;
             break;
         }
     }
     $this->lastCounterOffset = $offset;
     return $valid;
 }