2016-11-28 16 views
0

TOTPコードを持つサイトにログインする必要があります。私はTOTPコードを取得する簡単なNodeJSスクリプトを作成しましたが、それは常に無効です。NodeJS - 無効なtotpコードの生成

var notp = require('notp'); 
var base32 = require('thirty-two'); 
var key = 'KEYHERE'; 
var token = notp.totp.gen(key, 30); 
console.log(token); 
var login = notp.totp.verify(token, key); 
if (!login) { 
    return console.log('Token invalid'); 
} 
console.log('Token valid, sync value is %s', login.delta); 

また、私は自分の時間を同期しています(私はそれを正しく行ったかどうかは分かりません)。誰かがこのコードを修正したり、サーバー上の時刻を同期させたりする手助けをしてくれましたか? Serverは、NPMモジュール時刻同期 例を使用することができますフランス

答えて

0

からです:

// create a timesync instance 
var ts = timesync({ 
    server: '...', // either a single server, 
    peers: [...] // or multiple peers 
}); 

// get notified on changes in the offset 
ts.on('change', function (offset) { 
    console.log('offset from system time:', offset, 'ms'); 
} 

// get the synchronized time 
console.log('now:', new Date(ts.now())); 
+0

がその助けを行いnotpを確認する必要がありますか? – AJS

+0

申し訳ありませんが、分かりません。 –

+0

totpコードを使用してトークンを検証していますか? – AJS

0

は、あなたが生成し

var notp = {}; 
    notp.gen = function(key, opt) { 
     opt = opt || {}; 
     var time = opt.time || 30; 
     var _t = Date.now(); 

     // Time has been overwritten. 
     if(opt._t) { 
      if(process.env.NODE_ENV != 'test') { 
       throw new Error('cannot overwrite time in non-test environment!'); 
      } 
      _t = opt._t; 
     } 

     // Determine the value of the counter, C 
     // This is the number of time steps in seconds since T0 
     opt.counter = Math.floor((_t/1000)/time); 

     return hotp.gen(key, opt); 
    }; 
notp.verify = function(token, key, opt) { 
    opt = opt || {}; 
    var time = opt.time || 30; 
    var _t = Date.now(); 

    // Time has been overwritten. 
    if(opt._t) { 
     if(process.env.NODE_ENV != 'test') { 
      throw new Error('cannot overwrite time in non-test environment!'); 
     } 
     _t = opt._t; 
    } 

    // Determine the value of the counter, C 
    // This is the number of time steps in seconds since T0 
    opt.counter = Math.floor((_t/1000)/time); 

    return hotp.verify(token, key, opt); 
}; 
module.exports.totp = totp; 
+0

こんにちは、私はそれを生成することはできません。私は既に私がログインしようとしているそのウェブサイトから私自身の鍵を持っています。 –

+0

あなたはあなたが取得しているエラーは何ですか?あなたはトークンの有効または無効を取得していますか?どこにnotpを使用していますか? –

関連する問題