add: HOTP.at and HOTP.verify functions

This commit is contained in:
lancegin
2017-06-30 14:21:19 +08:00
parent c3e644a546
commit ad67a82794
3 changed files with 16 additions and 8 deletions
+9 -2
View File
@@ -22,7 +22,8 @@ export class HOTP extends OTP {
* ```
*/
at(count) {
return "HOTP.at";
let digit = super.generate_otp(count);
return digit;
}
/*
@@ -47,6 +48,12 @@ export class HOTP extends OTP {
* ```
*/
verify(otp, counter) {
return "HOTP.verify";
let otp_count = this.at(counter);
if (otp === otp_count) {
return true;
} else {
return false;
}
}
}
+6 -5
View File
@@ -4,17 +4,18 @@ var assert = require('assert');
describe('HOTP module test', function() {
var HOTP = hotp.HOTP;
var a = new HOTP("BASE32_ENCODED_SECRET");
var a = new HOTP("J22U6B3WIWRRBTAV");
describe('at() function', function() {
it("should print 'HOTP.at'", function() {
assert.equal("HOTP.at", a.at());
it("should return string", function() {
assert.equal("string", typeof(a.at(0)));
});
});
describe('verify() function', function() {
it("should print 'HOTP.verify'", function() {
assert.equal("HOTP.verify", a.verify());
it("should verify the digit", function() {
assert.equal(true, a.verify(a.at(0), 0));
assert.equal(false, a.verify(a.at(0), 1));
})
})
});
+1 -1
View File
@@ -13,7 +13,7 @@ describe('TOTP module test', function() {
});
describe('verify() function', function() {
it("should print 'TOTP.verify'", function() {
it("should verify the digit", function() {
assert.equal(true, a.verify(a.now()));
})
})