Skip to content

p455555555/totp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm version

TOTP

TOTP算法JavaScript实现,可以用于Node.js、浏览器、React Native环境,支持动态密码生成、效验, 可以搭配Google Authenticator使用

更新日志

  • [2019.12.11] HMAC加密库由Node.js Cypto模块替换为JavaScript实现的HMACSHA1加密库,现在支持在任何JavaScript环境使用了。

安装

$ npm install @nest-public/totp --save

用法

import totp from '@nest-public/totp';

// 设置密钥
const testKey = 'LFLFMU2SGVCUIUCZKBMEKRKLIQ';

// 获取6位动态密码
console.log(totp.totp(testKey));
// 返回 6位数字符串 如123456

// 效验动态密码
console.log(totp.totpVerify('123456', testKey));
// 返回 {
// 	status: true; // 验证码是否准确
// 	delta: 0; // 偏移量(1单位==30秒)
// }

测试

# jest 测试
$ npm run test

About

TOTP算法Javascript实现,支持动态密码生成、效验,可以搭配Google Authenticator使用

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published