@perryrh0dan/2fa
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

2FA

TOTP and HOTP package for nodejs

Descriptions

2fa is a zero dependency node.js package for generating and verifying one-time passwords. It can be used to implement two-factor (2FA) or multi-factor(MFA) authentication methods in anywhere that requires users to log in.

Open MFA standards are defined in RFC 4226 (HOTP: An HMAC-Based One-Time Password Algorithm) and in RFC 6238 (TOTP: Time-Based One-Time Password Algorithm). GOTP implements server-side support for both of these standards.

Highlights

Contents

Install

npm install @perryrh0dan/2fa

Usage

Time-based OTPs

// Generate secret
secret = generateSecret({ label: "accountName", issuer: "issuerName" })

// Generate code
code = totpGenerate({ secret: secret.secret })

// Verify code
totpVerify({ secret: secret.secret, token: code) //true

// Generate a provisioning URI
secret.otpauthURL()
// otpauth://totp/issuerName:accountName?secret=4S62BZNFXXSZLCRO&issuer=issuerName

Counter-based OTPs

// Generate secret
secret = generateSecret({ label: "accountName", issuer: "issuerName" })

// Generate code at counter
code = hotpGenerate(secret.secret, counter)

// Verify code
hotpVerify({ secret: secret.secret, token: code, counter: counter}) //true

// Generate a provisioning URI
secret.otpauthURL({ counter: counter })
// otpauth://hotp/issuerName:accountName?secret=4S62BZNFXXSZLCRO&issuer=issuerName&counter=counter

Development

Team

License

MIT

This repository was generated by tmpo

Package Sidebar

Install

npm i @perryrh0dan/2fa

Weekly Downloads

4

Version

1.0.2

License

MIT

Unpacked Size

30.8 kB

Total Files

26

Last publish

Collaborators

  • perryrh0dan