# gen-otp

> OTP generation package with expiration time in-build

Latest version **1.0.4** (published 2023-11-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install gen-otp
pnpm add gen-otp
yarn add gen-otp
bun add gen-otp
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2023-11-06 |
| First published | 2023-09-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Febin Joseph |
| Maintainers | febinjoseph |
| Keywords | otp, otp generation with expiration, otp generator, authenticator, one time password, generator, genotp |

## Links

- npm: https://www.npmjs.com/package/gen-otp
- Repository: https://github.com/Febin-Joseph/OTP-generator-npm_package
- Homepage: https://github.com/Febin-Joseph/OTP-generator-npm_package#readme
- Issues: https://github.com/Febin-Joseph/OTP-generator-npm_package/issues
- npm.io page: https://npm.io/package/gen-otp

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2023-11-06
- 1.0.3 — 2023-09-09
- 1.0.2 — 2023-09-09
- 1.0.1 — 2023-09-08
- 1.0.0 — 2023-09-08

## README

# OTP-generator


## Installation

#### To install the package, run the following command:

   ```bash
 npm i gen-otp
```


it is a simple OTP generation and it's exiration project and developers can simply integrate it
to their project for OTP verifications and they can customize the OTP expiration time and values
of the OTP and also can customize the length of the OTP as their wish :

## developers can use it like so  

  ```javascript
import generateOTP from 'gen-otp';

   //Generates OTP
        const genOTP = generateOTP({
            length: 4,
            digits: true,
            letters: true,
            symbols: true,
            expiration: '3m', //OTP expires in 3 minutes
        })
        
    console.log(genOTP)
```


## output

```javascript
{ otp: '482113', expiresAt: 2023-09-08T07:32:22.359Z }
```


## if doesn't added any value to true it will make an error

```javascript
 let charset = '';
  if (digits) charset += '0123456789';
  if (letters) charset += 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  if (symbols) charset += '!@#$%^&*()_+-=[]{}|;:,.<>?';

  if (!charset) {
    throw new Error('At least one character type (digits, letters, symbols) must be selected.');
  }
```

## and if also the length is less than 1 make an error

```javascript
if (length <= 0) {
    throw new Error('OTP length must be greater than 0.');
  }
```


## Bonus idea of the Package


| value         | Type     | Default Value  | Description                                                                   |
| -----------   | -------- | -------------- | -----------------------------------------------------------------             |
| length        | Number   | 0              | the length must be greater than or equal to one else throw an error           |
| digits        | Boolean  | true           | Boolean. default value true and needed to select one of this                  |
| letters       | Boolean  | false          | Boolean. Whether the password must contain at least one number.               |  
| symbols       | Boolean  | false          | Boolean. defaultly fale and if true shows symbols                             |
| expiration    | Number   | 0              | needed to enter only s for second m for minute and h for hours (Eg:1s,1m,1h)  |


#### The **generateOTP** function returns an object with two properties:
- `otp`: The OTP generated by the function by the customizations of the developer.
- `expiresAt`: If entered the expiration time it will be showing if doesn't entered no expiration for the otp.

---
_Source: https://npm.io/package/gen-otp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
