mirror of https://github.com/keeweb/keeweb.git
hotp
This commit is contained in:
parent
b3ee43e519
commit
737d4df8e6
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue