README
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
- Thomas Pöhlmann (@perryrh0dan)
License
This repository was generated by tmpo