Class RecoveryCodeGenerator

java.lang.Object
com.iizix.totp.RecoveryCodeGenerator

public class RecoveryCodeGenerator extends Object
Generates the recovery codes of a user with a second factor: the codes that sign the user in when the authenticator app is lost. Each code is used once. The codes are shown to the user once, when they are generated, and only a hash of each is kept (SignIn L-6).

Until SignIn L-6 this class and its method were package-private, so nothing outside com.iizix.totp could call them, and nothing did.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The number of characters of a recovery code without its dashes: 16.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String[]
    generateCodes(int amount)
    Generates recovery codes in a certain amount.
    static String
    Brings a recovery code as a user typed it to the form it is hashed in: the dashes and all whitespace are removed and the letters are made upper case, so that 4ckn xspn-et8t xgr0 and 4CKN-XSPN-ET8T-XGR0 are the same code.
  • Field Details

    • LENGTH

      public static final int LENGTH
      The number of characters of a recovery code without its dashes: 16.
      See Also:
  • Constructor Details

    • RecoveryCodeGenerator

      public RecoveryCodeGenerator()
  • Method Details

    • generateCodes

      public static String[] generateCodes(int amount)
      Generates recovery codes in a certain amount.
      Parameters:
      amount - The amount of recovery codes.
      Returns:
      The array of recovery codes.
    • normalize

      public static String normalize(String typed)
      Brings a recovery code as a user typed it to the form it is hashed in: the dashes and all whitespace are removed and the letters are made upper case, so that 4ckn xspn-et8t xgr0 and 4CKN-XSPN-ET8T-XGR0 are the same code.
      Parameters:
      typed - The code as typed, null for none.
      Returns:
      The LENGTH characters of the code, or null when what was typed is not a recovery code: another length, or a character no code is made of.