Speakeasy Demo

Secret Key

Sample Code

var speakeasy = require('speakeasy');
var QRCode = require('qrcode');

var secret = speakeasy.generateSecret({length: 20});
console.log(secret.base32); // secret of length 20

QRCode.toDataURL(secret.otpauth_url, function(err, data_url) {
  console.log(data_url); // get QR code data URL
});

Generated Token

Sample Code

// Get the token at the current time
// Here, we specify base32 encoding

var token = speakeasy.totp({
  secret: secret.base32,
  encoding: 'base32'
});

console.log(token);

Verify Token

Sample Code

var userToken = params.get('token'); // Verify the token the user gives

var verified = speakeasy.totp.verify({
  secret: secret.base32,
  encoding: 'base32',
  token: userToken
});

console.log(verified);

Secret (base 32 format):

KRKDMS3LJYQVG53UJFPFQUSOPEYESKTN

Scan this in to Google Authenticator or another two-factor authentication app.

781459

Updating...