Skip to content

Commit

Permalink
Fix bug when v is < 1000000 and substr fails
Browse files Browse the repository at this point in the history
For v less 1m e.g. 12345 previous code would try to get substr(-1,6). This happens once in 2130 attempts.
  • Loading branch information
homakov committed Aug 5, 2015
1 parent ce01754 commit 1ca7eb1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -43,9 +43,9 @@ hotp.gen = function(key, opt) {
(h[offset + 2] & 0xff) << 8 |
(h[offset + 3] & 0xff);

v = v + '';
v = (v % 1000000) + '';

return v.substr(v.length - p, p);
return Array(7-v.length).join('0') + v;
};

/**
Expand Down

0 comments on commit 1ca7eb1

Please sign in to comment.