Fixed issue causing negative counter values to be rejected

This commit is contained in:
Guy Halford-Thompson 2012-06-13 17:38:47 +00:00
parent b889c99a1e
commit 13865d89d5
2 changed files with 7 additions and 1 deletions

View File

@ -82,7 +82,7 @@ hotp.verify = function(token, key, opt) {
// Now loop through from C to C + W to determine if there is
// a correct code
for(var i = counter; i <= counter + window; ++i) {
for(var i = counter - window; i <= counter + window; ++i) {
opt.counter = i;
if(this.gen(key, opt) === token) {
// We have found a matching code, trigger callback

View File

@ -132,6 +132,12 @@ exports.testHOTPOutOfSync = function(beforeExit, assert) {
// counterheck that the test should pass for window >= 9
opt.window = 8;
assert.ok(notp.hotp.verify(token, key, opt), 'Should pass for value of window >= 9');
// counterheck that test should pass for negative counter values
token = '755224';
opt.counter = 7
opt.window = 8;
assert.ok(notp.hotp.verify(token, key, opt), 'Should pass for negative counter values');
};