ts-totp

TOTP动态口令

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
ts-totp
1.1.13 months ago4 months agoMinified + gzip package size for ts-totp in KB

Readme

ts-totp
!NPM versionnpm-imagenpm-url !Known Vulnerabilitiessnyk-imagesnyk-url !npm downloaddownload-imagedownload-url

Description

Generate a dynamic password and verify that the password is valid within a specified time

Installation

  1. yarn add ts-totp

Description

```js // totp使用说明 import { getToken, validate } from 'ts-totp'; / @param {string} secret 密钥. @param {number} config.digits=6 生成的token长度. @param {number} config.interval=60 口令有效期,单位秒,默认60秒. / // 生成动态口令 const token = getToken({ secret: 'K33DFSsasdassssVS', digits: 10, interval: 60 }); // token = 1950901855 // 校验口令 const res = validate(token, { secret: 'K33DFSsasdassssVS', digits: 10, interval: 60 }); // res = true ``` ```js // 携带参数校验使用说明 import { getCode, validateCode } from 'ts-totp'; / prefix string 前缀 secret string 密钥 digits number 验证码位数 interval number 验证码有效时间 num number 验证数字(自动查找其临近的质数) type string 质数查找方式(up/down)up:向上查找,小于该数的最大质数 down:向下查找,大于该数的最小质数 data number 携带的信息,比如用户ID.数字要小于num。如:当前系统设计最大承受用户有96742人,则num可以设定必须大于96742的数值(96743) / const config = { prefix: '10', secret: 'K33DFSsssssVS', digits: 10, interval: 60, num: 96743, type: 'down' }; // 生成带参口令 const params = Object.assign({ data: 1002 }, config); const code = getCode(params); // code = 129477686511008 // 校验口令 const res = validateCode(code, config); //成功 res = { message: 'success', data: 1002, token: 1338284494 } //失败 res = { message: 'fail' } ```

Contribution

  1. Fork the repository
  1. Create Featxxx branch
  1. Commit your code
  1. Create Pull Request

Gitee Feature

  1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
  1. Gitee blog blog.gitee.com
  1. Explore open source project https://gitee.com/explore
  1. The most valuable open source project GVP
  1. The manual of Gitee https://gitee.com/help
  1. The most popular members https://gitee.com/gitee-stars/