1.1.2 • Published 1 year ago

otp-gen-agent v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

otp-gen-agent

A small and secure one time password (otp) generator for Javascript based on nanoid.

NPM

contributions welcome npm version License

Installation

npm install otp-gen-agent --save

Usage

Mobile number has become the defacto user authentication mechanism in India and hence, OTP generation is a very common phenomena. This is a small utility lib to generate OTP.

default

const { otpGen } = require('otp-gen-agent');

const otp = await otpGen(); // '344156'  (OTP length is 6 digit by default)
  • Default OTP lenght is 6
  • Default characters used to generate OTP is 0123456789

custom otp generator

const { customOtpGen } = require('otp-gen-agent');

const otp = await customOtpGen({length: 4, chars: 'abc123'}); // 'a3c1'

Arguments:

  • options: optional
    • length: custom otp length
    • chars: custom characters

You can customise the OTP length and also the characters to be used for OTP generation.

  • Default OTP lenght is 6.
  • Default characters used to generate OTP is 0123456789

bulk otp generator

const { bulkOtpGen } = require('otp-gen-agent');

const otp = await bulkOtpGen(2); // Array of otps: ['344156', '512398']
const { bulkOtpGen } = require('otp-gen-agent');

const otp = await bulkOtpGen(2, {length = 5, chars: 'abcd123'} ); // Array of otps: ['312b3', 'bcddd']

Arguments:

  • num: number of OTPs to be generated in bulk
  • opts: optional argument
    • length: custom otp length (default: 6)
    • chars: custom characters (default: 0123456789)

Useful in cases where number of OTPs to be generated is known before hand.

Test

npm run test

License

MIT

If you find this utility library useful, you can buy me a coffee to keep me energized for creating libraries like this.

1.1.1

1 year ago

1.1.2

1 year ago

1.1.0

1 year 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.1

2 years ago

1.0.0

2 years ago