otplib.test.js
483 Bytes
/**
* Created by lintry on 2017/5/19.
*/
//用到了eval函数,不能在小程序内使用
const authenticator = require('otplib/authenticator').default;
console.log(authenticator)
authenticator.options.algorithm = 'sha1'
authenticator.options.encoding = 'base32'
const secret = authenticator.generateSecret();
const token = authenticator.generate('FA7HM4ZZG5AF4JSVHQ4XOVC6KFGVAMRZ');
const isValid = authenticator.check(123456, secret);
console.log(token, secret, isValid)