Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@frani/totp

frani1MIT1.0.2

Time based One Time Password generator code - this is a no-depenencies package

otp, totp, time based one time password, one time password, no depenencies, no deps

readme

Time based One Time Password

Simple TOTP, one function to call and generate OTP token.

This is a no-depenencies package

Install

if you are using Yarn:

yarn add @frani/totp

if you are using NPM:

npm i @frani/totp

Usage

to generate:

const totp = require("@frani/totp");

const token = totp.generate({
  secret: "123", // optional - default is 'secret'
  timeStep: 30, // optional - default is 30 seconds
  digits: 6, // optional - default is 6
});
console.log(token); // 480143

in case you want to compare, simple regenerate and check with '===', example:

const totp = require("@frani/totp");

const CODE = "123123";

const token = totp.generate({
  secret: "123", // optional - default is 'secret'
  timeStep: 30, // optional - default is 30 seconds
  digits: 6, // optional - default is 6
});
console.log(token); // 480143

if (CODE === token) return true; // is false