totp-generator 允许你从一个TOTP密钥生成TOTP令牌
项目基于openharmony api10 开发
推荐使用《MFA二次验证码》微信小程序版本,完美兼容 GoogleAuthenticator的二次验证器, 终身免费的云服务使您远离丢失数据的烦恼。
使用微信扫码即可使用
欢迎 Star,项目的发展离不开你的鼓励
https://github.com/taosiqi/oh-mfa.git
ohpm install totp-generator
import { generateTotp } from 'totp-generator'
const token = generateTotp("JBSWY3DPEHPK3PXP");
console.log(token); // prints a 6-digit time-based token based on provided key and current time
- SHA1
- 30秒的时代间隔
- 6位数字令牌
可以提供一个可选的第二个参数来设置:
import { generateTotp } from '@ohos/totp-generator'
const token = generateTotp("JBSWY3DPEHPK3PXP", { digits: 8 });
console.log(token); // prints an 8-digit token
const token = generateTotp("JBSWY3DPEHPK3PXP", { algorithm: "SHA512" });
console.log(token); // prints a token created using a different algorithm
const token = generateTotp("JBSWY3DPEHPK3PXP", { period: 60 });
console.log(token); // prints a token using a 60-second epoch interval
const token = generateTotp("JBSWY3DPEHPK3PXP", { timestamp: 1465324707000 });
console.log(token); // prints a token for given time
const token = generateTotp("JBSWY3DPEHPK3PXP", {
digits: 8,
algorithm: "SHA512",
period: 60,
timestamp: 1465324707000,
});
console.log(token); // prints a token using all custom settings combined
- TOTP生成
- 端到端测试(在需要使用两因素认证登录的地方)