generateTOTPCode method

int generateTOTPCode (
  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

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 SHA1) These settings are defaulted to the RFC standard but can be changed.

Implementation

static int generateTOTPCode(String secret, int time,
    {int length = 6,
    int interval = 30,
    Algorithm algorithm = Algorithm.SHA256,
    bool isGoogle = false}) {
  time = (((time ~/ 1000).round()) ~/ interval).floor();
  return _generateCode(secret, time, length, getAlgorithm(algorithm),
      _getAlgorithmByteLength(algorithm), isGoogle: isGoogle);
}