Skip to content

paritosh9199/totp-gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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";
 }

About

A TOTP secret, token generator and verifier!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published