/** * Create a HOTP 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 HotpConfigurationInterface $configuration The HOTP configuration. * @param CounterBasedOtpSharedParametersInterface $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 HOTP URI. */ public function createHotp(HotpConfigurationInterface $configuration, CounterBasedOtpSharedParametersInterface $shared, $label, $issuer = null, $issuerInLabel = null) { if (1 === $shared->counter()) { $parameters = ''; } else { $parameters = '&counter=' . rawurlencode($shared->counter()); } return $this->buildUri('hotp', $parameters, $configuration, $shared, $label, $issuer, $issuerInLabel); }
/** * Generate an HOTP value. * * @link http://tools.ietf.org/html/rfc4226#section-5.3 * * @param HotpConfigurationInterface $configuration The configuration to use for generation. * @param CounterBasedOtpSharedParametersInterface $shared The shared parameters to use for generation. * * @return HotpValueInterface The generated HOTP value. */ public function generateHotp(HotpConfigurationInterface $configuration, CounterBasedOtpSharedParametersInterface $shared) { return new HotpValue(hash_hmac($configuration->algorithm()->value(), $this->pack($shared->counter()), $shared->secret(), true)); }