totp-mfa
v1.1.1
Published
Node package to generate and verify MFA TOTP based on MFA Secret
Downloads
14
Readme
MFA TOTP
Node package to generate and verify an MFA Time-Based One-Time Password based on a secret.
Installation
npm install totp-mfa
Usage
Generating a Time-Based One-Time Password
const { getTOTP } = require('totp-mfa');
// Generate a random base32 secret (you can use your own method or library)
const secret = 'JBSWY3DPEHPK3PXP'; // Example secret
// Generate TOTP
const totp = getTOTP(secret);
console.log(`Generated TOTP: ${totp}`);
Verify a Time-Based One-Time Password
const { verifyTOTP } = require('totp-mfa');
// Use the same secret as used for generating the TOTP
const secret = 'JBSWY3DPEHPK3PXP'; // Example secret
// TOTP to verify
const totp = '123456'; // Example TOTP
// Verify TOTP
const isValid = verifyTOTP(secret, totp);
console.log(`Is TOTP valid? ${isValid}`);
Get the validity of a Time-Based One-Time Password
const { getTOTP, verifyTOTP, getTOTPValidity } = require('totp-mfa');
const secret = 'JBSWY3DPEHPK3PXP'; // Example secret
const totp = getTOTP(secret);
console.log(`Generated TOTP: ${totp}`);
const remainingTime = getTOTPValidity();
console.log(`TOTP is valid for another ${remainingTime} seconds.`);