1.1.1 • Published 2 years ago

ts-totp v1.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

ts-totp

NPM version Known Vulnerabilities npm download

Description

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

Installation

  1. yarn add ts-totp

Description

// 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
// 携带参数校验使用说明
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
  2. Create Feat_xxx branch
  3. Commit your code
  4. Create Pull Request

Gitee Feature

  1. You can use Readme_XXX.md to support different languages, such as Readme_en.md, Readme_zh.md
  2. Gitee blog blog.gitee.com
  3. Explore open source project https://gitee.com/explore
  4. The most valuable open source project GVP
  5. The manual of Gitee https://gitee.com/help
  6. The most popular members https://gitee.com/gitee-stars/
1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago