Esempio n. 1
0
 /**
  * Validate a set of multi-factor authentication parameters.
  *
  * @param MfaConfigurationInterface    $configuration The configuration to use for validation.
  * @param MfaSharedParametersInterface $shared        The shared parameters to use for validation.
  * @param MfaCredentialsInterface      $credentials   The credentials to validate.
  *
  * @return Result\MfaValidationResultInterface The validation result.
  */
 public function validate(MfaConfigurationInterface $configuration, MfaSharedParametersInterface $shared, MfaCredentialsInterface $credentials)
 {
     if (strlen($credentials->password()) !== $configuration->digits()) {
         return new TimeBasedOtpValidationResult(TimeBasedOtpValidationResult::CREDENTIAL_LENGTH_MISMATCH);
     }
     for ($i = -$configuration->pastWindows(); $i <= $configuration->futureWindows(); ++$i) {
         $currentShared = clone $shared;
         $currentShared->setTime($shared->time() + $i * $configuration->window());
         $value = $this->generator()->generate($configuration, $currentShared);
         if ($credentials->password() === $value->string($configuration->digits())) {
             return new TimeBasedOtpValidationResult(TimeBasedOtpValidationResult::VALID, $i);
         }
     }
     return new TimeBasedOtpValidationResult(TimeBasedOtpValidationResult::INVALID_CREDENTIALS);
 }
Esempio n. 2
0
 /**
  * Validate a set of multi-factor authentication parameters.
  *
  * @param MfaConfigurationInterface    $configuration The configuration to use for validation.
  * @param MfaSharedParametersInterface $shared        The shared parameters to use for validation.
  * @param MfaCredentialsInterface      $credentials   The credentials to validate.
  *
  * @return Result\MfaValidationResultInterface The validation result.
  */
 public function validate(MfaConfigurationInterface $configuration, MfaSharedParametersInterface $shared, MfaCredentialsInterface $credentials)
 {
     if (strlen($credentials->password()) !== $configuration->digits()) {
         return new CounterBasedOtpValidationResult(CounterBasedOtpValidationResult::CREDENTIAL_LENGTH_MISMATCH);
     }
     for ($counter = $shared->counter(); $counter <= $shared->counter() + $configuration->window(); ++$counter) {
         $currentShared = clone $shared;
         $currentShared->setCounter($counter);
         $value = $this->generator()->generate($configuration, $currentShared);
         if ($credentials->password() === $value->string($configuration->digits())) {
             return new CounterBasedOtpValidationResult(CounterBasedOtpValidationResult::VALID, $counter + 1);
         }
     }
     return new CounterBasedOtpValidationResult(CounterBasedOtpValidationResult::INVALID_CREDENTIALS);
 }