Interface TwoFactorPasswordGenerator

  • All Known Implementing Classes:
    MockTwoFactorPasswordGenerator, TwoFactorPasswordGeneratorImpl

    public interface TwoFactorPasswordGenerator
    Generates TOTP passwords (RFC 6238) with HMAC algorithm for two-factor authentication by secret key and timestamp The hash function that is used in HMAC is SHA-1 (Can be extended to SHA-2 family, depends on authenticator apps).
    Author:
    Daniil Boger
    • Method Detail

      • generatePasswords

        @NotNull
        Set<Integer> generatePasswords​(@NotNull
                                       String secretKey,
                                       long timestampSec)
        Generates and returns all TOTP passwords that will be considered as correct, using secret key and UNIX timestamp. The multiple correct passwords are allowed to prevent time desynchroniation between client and server. For example, password from previous 30-sec. epoch can be allowed.
        Parameters:
        secretKey - secret key
        timestampSec - current UNIX timestamp in seconds
        Returns:
        set of all correct password
      • generateSecretKey

        @NotNull
        String generateSecretKey()
        Generates secret key with cryptographically strong generator
        Returns:
        generated secret key
      • generateRecoveryKeys

        @NotNull
        Set<String> generateRecoveryKeys()
        Generates set of recovery keys with cryptographically strong generator.
        Returns:
        set with generated recovery keys