forked from github/jsotp
add: HOTP.at and HOTP.verify functions
This commit is contained in:
parent
c3e644a546
commit
ad67a82794
11
src/hotp.js
11
src/hotp.js
@ -22,7 +22,8 @@ export class HOTP extends OTP {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
at(count) {
|
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) {
|
verify(otp, counter) {
|
||||||
return "HOTP.verify";
|
let otp_count = this.at(counter);
|
||||||
|
|
||||||
|
if (otp === otp_count) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,17 +4,18 @@ var assert = require('assert');
|
|||||||
describe('HOTP module test', function() {
|
describe('HOTP module test', function() {
|
||||||
|
|
||||||
var HOTP = hotp.HOTP;
|
var HOTP = hotp.HOTP;
|
||||||
var a = new HOTP("BASE32_ENCODED_SECRET");
|
var a = new HOTP("J22U6B3WIWRRBTAV");
|
||||||
|
|
||||||
describe('at() function', function() {
|
describe('at() function', function() {
|
||||||
it("should print 'HOTP.at'", function() {
|
it("should return string", function() {
|
||||||
assert.equal("HOTP.at", a.at());
|
assert.equal("string", typeof(a.at(0)));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('verify() function', function() {
|
describe('verify() function', function() {
|
||||||
it("should print 'HOTP.verify'", function() {
|
it("should verify the digit", function() {
|
||||||
assert.equal("HOTP.verify", a.verify());
|
assert.equal(true, a.verify(a.at(0), 0));
|
||||||
|
assert.equal(false, a.verify(a.at(0), 1));
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -13,7 +13,7 @@ describe('TOTP module test', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('verify() function', function() {
|
describe('verify() function', function() {
|
||||||
it("should print 'TOTP.verify'", function() {
|
it("should verify the digit", function() {
|
||||||
assert.equal(true, a.verify(a.now()));
|
assert.equal(true, a.verify(a.now()));
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user