2FA
Module for generating and verifying 2FA codes (specifically TOTP and HOTP).
Also contains utilities for handing 2FA logic, such as generating Google Authenticator compatible QR codes (without going via Google Charts) and generating backup codes.
Install
npm install --save 2fa
Usage
var tfa = require('2fa');
tfa.generateKey(32, function(err, key) {
tfa.generateBackupCodes(8, 'xxxx-xxxx-xxxx', function(err, codes) {
});
tfa.generateGoogleQR('Company', 'email@gmail.com', key, function(err, qr) {
});
var opts = {
beforeDrift: 2,
afterDrift: 2,
drift: 4,
step: 30
};
var counter = Math.floor(Date.now() / 1000 / opts.step);
var code = tfa.generateCode(key, counter);
var validHOTP = tfa.verifyHOTP(key, code, counter, opts);
var validTOTP = tfa.verifyTOTP(key, code, opts);
});