Class MGL_OtpProvider

java.lang.Object
tech.mgl.utils.security.gen.MGL_OtpProvider
All Implemented Interfaces:
OtpSource

public class MGL_OtpProvider extends Object implements OtpSource
Class containing implementation of HOTP/TOTP. Generates OTP codes for one or more accounts.
Author:
HOTPOT (hotpot@mgl.tech)
  • Field Details

    • DEFAULT_INTERVAL

      public static final int DEFAULT_INTERVAL
      Default passcode timeout period (in seconds)
      See Also:
  • Constructor Details

    • MGL_OtpProvider

      public MGL_OtpProvider()
    • MGL_OtpProvider

      public MGL_OtpProvider(int interval)
  • Method Details

    • getNextCode

      public String getNextCode(String accountName, String key) throws OtpSourceException
      Description copied from interface: OtpSource
      Return the next OTP code for specified username. Invoking this function may change internal state of the OTP generator, for example advancing the counter.
      Specified by:
      getNextCode in interface OtpSource
      Parameters:
      accountName - Username, email address or other unique identifier for the account.
      Returns:
      OTP as string code.
      Throws:
      OtpSourceException
    • respondToChallenge

      public String respondToChallenge(String accountName, String key, String challenge) throws OtpSourceException
      Description copied from interface: OtpSource
      Generate response to a given challenge based on next OTP code. Subclasses are not required to implement this method.
      Specified by:
      respondToChallenge in interface OtpSource
      Parameters:
      accountName - Username, email address or other unique identifier for the account.
      challenge - Server specified challenge as UTF8 string.
      Returns:
      Response to the challenge.
      Throws:
      OtpSourceException
    • getTotpCounter

      public TotpCounter getTotpCounter()
      Description copied from interface: OtpSource
      Gets the counter for generating or verifying TOTP codes.
      Specified by:
      getTotpCounter in interface OtpSource
    • enumerateAccounts

      public int enumerateAccounts(Collection<String> result)
      Description copied from interface: OtpSource
      Enumerate list of accounts that this OTP token supports.
      Specified by:
      enumerateAccounts in interface OtpSource
      Parameters:
      result - Collection to append usernames. This object is NOT cleared on entry; if there are existing items, they will not be removed.
      Returns:
      Number of accounts added to the collection.