generateTOTPCodeString static method Null safety

String generateTOTPCodeString(
  1. String secret,
  2. int time,
  3. {int length = 6,
  4. int interval = 30,
  5. Algorithm algorithm = Algorithm.SHA256,
  6. bool isGoogle = false}
)

Generates a Time-based one time password code and return as a 0 padded string.

Takes current time in milliseconds, converts to seconds and devides it by interval to get a code every iteration of the interval. A interval of 1 will be the same as if passing time into the HOTPCode function..

Optional parameters to change the length of the code provided (default 6), interval (default 30), and hashing algorithm (default SHA256) 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 generateTOTPCodeString(String secret, int time,
    {int length = 6,
    int interval = 30,
    Algorithm algorithm = Algorithm.SHA256,
    bool isGoogle = false}) {
  final code =
      '${generateTOTPCode(secret, time, length: length, interval: interval, algorithm: algorithm, isGoogle: isGoogle)}';
  return code.padLeft(length, '0');
}