generateHOTPCodeString static method Null safety

String generateHOTPCodeString(
  1. String secret,
  2. int counter,
  3. {int length = 6,
  4. Algorithm algorithm = Algorithm.SHA1,
  5. bool isGoogle = false}
)

Generates a one time password code based on a counter you provide and increment, returns as a 0 padded string.

This function does not increment for you. Optional parameters to change the length of the code provided (default 6) and hashing algorithm (default SHA1) These settings are defaulted to the RFC standard but can be changed. Throws a FormatException if string is not a base32 secret.

Implementation

static String generateHOTPCodeString(String secret, int counter,
    {int length = 6,
    Algorithm algorithm = Algorithm.SHA1,
    bool isGoogle = false}) {
  final code =
      '${generateHOTPCode(secret, counter, length: length, algorithm: algorithm, isGoogle: isGoogle)}';
  return code.padLeft(length, '0');
}