Permalink
Browse files

Fixed issue causing negative counter values to be rejected

  • Loading branch information...
1 parent b889c99 commit 13865d89d5159ef1339be22a5f26c12b0088a635 @guyht committed Jun 13, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 index.js
  2. +6 −0 test/notp.js
View
@@ -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
@@ -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');
};

0 comments on commit 13865d8

Please sign in to comment.