This commit is contained in:
antelle 2016-04-02 00:16:23 +03:00
parent b3ee43e519
commit 737d4df8e6
2 changed files with 13 additions and 7 deletions

View File

@ -40,13 +40,19 @@ var Otp = function(url, params) {
};
Otp.prototype.next = function(callback) {
var now = Date.now();
var epoch = Math.round(now / 1000);
var time = Math.floor(epoch / this.period);
var msPeriod = this.period * 1000;
var timeLeft = msPeriod - (now % msPeriod);
var valueForHashing;
var timeLeft;
if (this.type === 'totp') {
var now = Date.now();
var epoch = Math.round(now / 1000);
valueForHashing = Math.floor(epoch / this.period);
var msPeriod = this.period * 1000;
timeLeft = msPeriod - (now % msPeriod);
} else {
valueForHashing = this.counter;
}
var data = new Uint8Array(8);
new DataView(data.buffer).setUint32(4, time);
new DataView(data.buffer).setUint32(4, valueForHashing);
var that = this;
this.hmac(data, function(sig, err) {
if (!sig) {

View File

@ -48,7 +48,7 @@ var FieldViewOtp = FieldViewText.extend({
}
this.otpValue = pass || '';
this.render();
if (this.otpValue) {
if (this.otpValue && timeLeft) {
this.otpTimeout = setTimeout(this.requestOtpUpdate.bind(this), timeLeft);
}
}