totp-gen

0.1.2 • Public • Published

totp-gen

A TOTP secret, token generator and verifier!


Installation

npm install --save totp-gen

How to use!

let totp = require('totp-gen');
 
/* Generate a secret BASE32 String */
let secretLength = 40;
let secret = totp.generateSecret(secretLength);
 
let time = Date.now();
let periodInSecond = 30;
let lengthOfPin = 6;
 
/* Generate a TOTP Token using SECRET, time, period and 
   length. 
*/
let totpToken = totp.generateTOTP(secret, time, periodInSecond, lengthOfPin);
 
let company = "MyExampleCompany";
let email = "abc@xyz.com";
 
/* Generate totp URL for authenticator  apps*/
let totpURL = totp.generateURL(company, email, secret, lengthOfPin, periodInSecond);
 
/* Verify generated token and secret */
if(totp.verifyToken(secret, totpToken, time, periodInSecond, lengthOfPin)){
    console.log(
        {
            secretLength,
            secret, 
            time,
            periodInSecond,
            lengthOfPin,
            totpToken,
            timeLeftForTokenValidity: totp.countdownTimer(periodInSecond),
            totpURL
        }
    )
 }else{
     throw "INVALID_TOKEN_VERIFICATION";
 }
 

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i totp-gen

    Weekly Downloads

    1

    Version

    0.1.2

    License

    GPL-3.0-or-later

    Unpacked Size

    8.43 kB

    Total Files

    5

    Last publish

    Collaborators

    • paritosh9199