Socket
Book a DemoInstallSign in
Socket

generateotp-ts

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generateotp-ts

A TypeScript library for generating and verifying OTPs using JWT

1.0.5
latest
Source
npmnpm
Version published
Weekly downloads
4
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

generateotp-ts

A TypeScript library for generating and verifying One-Time Passwords (OTPs) using JSON Web Tokens (JWT).

Features

  • Generate n-digit OTPs
  • Set custom expiration time for OTPs
  • Verify OTPs with tokens
  • Encode and decode OTPs using JWT

Installation

Install generateotp-ts using npm:

npm install generateotp-ts

Usage

Import and use the generateOtp and verifyOtp functions in your TypeScript or JavaScript project:

import { generateOtp, verifyOtp } from "generateotp-ts";

// Generate a 6-digit OTP with a 5-minute expiration time
const { otp, token } = generateOtp(6, "5m");

console.log("Generated OTP:", otp);
console.log("Token:", token);

// Verify the OTP with the token
const isValidOtp = verifyOtp(otp, token);

console.log("Is OTP valid?", isValidOtp);

generateOtp()

The generateOtp() function generates an n-digit OTP and returns an object containing the generated OTP and its corresponding JWT-encoded token.

Function signature:

function generateOtp(
  digits: number,
  expiration: string | number | undefined = undefined,
  secret: string = ""
): { otp: number; token: string };

verifyOtp()

The verifyOtp() function verifies the provided OTP against the JWT-encoded token and returns true if it's valid, or false if it's invalid or expired.

Function signature:

function verifyOtp(otp: number, token: string, secret: string = ""): boolean;

Keywords

otp

FAQs

Package last updated on 19 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.