cia*_*ben 4 security one-time-password node.js google-authenticator
我使用以下命令在我的节点应用程序中生成一个简单的令牌notp:
var notp = require('notp')
notp.totp.gen("ciao", {}) // => 345678
Run Code Online (Sandbox Code Playgroud)
我想构建一个类似于 Google Authenticator 提供的可视化效果,并且我需要知道生成的 otp 过期的秒数(或日期时间)。
我该怎么做?
cia*_*ben 11
我已经找到了如何做到这一点,实际上非常简单,您只需要知道算法使用的开始时间即可。
事实证明,Google Authenticator 使用 Unix Epoch,因此就我而言,要显示计时器,我可以执行以下操作:
setInterval(() => (console.log(30 - Math.round(new Date() / 1000) % 30)), 1000)
Run Code Online (Sandbox Code Playgroud)