Пример #1
0
 /**
  * Construct a new TOTP configuration.
  *
  * @param integer|null           $digits        The number of password digits.
  * @param integer|null           $window        The number of seconds each token is valid for.
  * @param integer|null           $futureWindows The number of future windows to check.
  * @param integer|null           $pastWindows   The number of past windows to check.
  * @param integer|null           $secretLength  The length of the shared secret.
  * @param HotpHashAlgorithm|null $algorithm     The underlying algorithm to use.
  *
  * @throws InvalidPasswordLengthException If the number of digits is invalid.
  */
 public function __construct($digits = null, $window = null, $futureWindows = null, $pastWindows = null, $secretLength = null, HotpHashAlgorithm $algorithm = null)
 {
     if (null !== $digits && $digits > 10) {
         throw new InvalidPasswordLengthException($digits);
     }
     if (null === $algorithm) {
         $algorithm = HotpHashAlgorithm::SHA1();
     }
     parent::__construct($digits, $window, $futureWindows, $pastWindows, $secretLength);
     $this->algorithm = $algorithm;
 }
 /**
  * Create an OTP URI for use with Google Authenticator.
  *
  * Note that this is not a URI for the QR code used by Google Authenticator.
  * The URI produced by this method is used as the actual content of the QR
  * code, and follows a special set of conventions understood by Google
  * Authenticator, and other OTP apps.
  *
  * @param string                          $type          The otp type identifier.
  * @param string                          $parameters    Additional URI parameters.
  * @param HotpBasedConfigurationInterface $configuration The OTP configuration.
  * @param OtpSharedParametersInterface    $shared        The shared parameters.
  * @param string                          $label         The label for the account.
  * @param string|null                     $issuer        The issuer name.
  * @param boolean|null                    $issuerInLabel True if legacy issuer support should be enabled by prefixing the label with the issuer name.
  *
  * @return string The OTP URI.
  */
 protected function buildUri($type, $parameters, HotpBasedConfigurationInterface $configuration, OtpSharedParametersInterface $shared, $label, $issuer = null, $issuerInLabel = null)
 {
     if (null === $issuerInLabel) {
         $issuerInLabel = false;
     }
     if (6 !== $configuration->digits()) {
         $parameters .= '&digits=' . rawurlencode($configuration->digits());
     }
     if (HotpHashAlgorithm::SHA1() !== $configuration->algorithm()) {
         $parameters .= '&algorithm=' . rawurlencode($configuration->algorithm()->value());
     }
     $legacyIssuer = '';
     if (null !== $issuer) {
         if ($issuerInLabel) {
             $legacyIssuer = rawurlencode($issuer) . ':';
         }
         $parameters .= '&issuer=' . rawurlencode($issuer);
     }
     return sprintf('otpauth://%s/%s%s?secret=%s%s', rawurlencode($type), $legacyIssuer, rawurlencode($label), rawurlencode(Base32::encode($shared->secret())), $parameters);
 }