Fix bug when v is < 1000000 and substr fails
For v less 1m e.g. 12345 previous code would try to get substr(-1,6). This happens once in 2130 attempts.
This commit is contained in:
parent
ce0175437a
commit
1ca7eb1739
4
index.js
4
index.js
@ -43,9 +43,9 @@ hotp.gen = function(key, opt) {
|
|||||||
(h[offset + 2] & 0xff) << 8 |
|
(h[offset + 2] & 0xff) << 8 |
|
||||||
(h[offset + 3] & 0xff);
|
(h[offset + 3] & 0xff);
|
||||||
|
|
||||||
v = v + '';
|
v = (v % 1000000) + '';
|
||||||
|
|
||||||
return v.substr(v.length - p, p);
|
return Array(7-v.length).join('0') + v;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user