verify method

bool verify({
  1. String? otp,
  2. int? counter,
})

Verifies the HOTP value passed in against the a given counter.

All parameters are mandatory.

HOTP hotp = HOTP(secret: 'BASE32ENCODEDSECRET');
hotp.at(counter: 0); // => 432143
// Verify for current time
hotp.verify(otp: 432143, counter: 0); // => true
// Verify after 30s
hotp.verify(otp: 432143, counter: 10); // => false

Implementation

bool verify({String? otp, int? counter}) {
  if (otp == null || counter == null) {
    return false;
  }

  String? otpCount = this.at(counter: counter);
  return otp == otpCount;
}