verify method

bool verify (String otp, [ DateTime time ])

Verifies the OTP passed in against the current time OTP.

@param {otp} @type {String} @desc the OTP waiting for checking

@param {time} @type {int or datetime} @desc Time to check OTP at (defaults to now)

@return {Boolean}

@example TOTP totp = dotp.TOTP('BASE32ENCODEDSECRET'); totp.now(); // => 432143 // Verify for current time totp.verify(432143); // => true // Verify after 30s totp.verify(432143); // => false

Implementation

bool verify(String otp, [DateTime time]) {
  DateTime _time = time;
  _time ??= DateTime.now();

  String otpTime = super.generateOTP(Util.timeFormat(_time, this.interval));
  if (otp == otpTime) {
    return true;
  }
  return false;
}