Skip to content

🎲TOTP(Time-based one-time password) generator, support for Google Authenticator

License

Notifications You must be signed in to change notification settings

wuyanxin/totp.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

totp.js

Two-factor authentication implementation in pure javascript. One-time password generator (HOTP/TOTP) with support for Google Authenticator.

Build Status Node.js >= 8.x MIT Licence

Live Demo

Preview

preview

Demo

Getting Started

Install

npm i totp.js

Node.js

const TOTP = require('totp.js');

// generate a base32 secret key
const key = TOTP.randomKey();
// 'GAXGGYT2OU2DEOJR'

const totp = new TOTP(key);
const code = totp.genOTP();
// '552179'
totp.verify(code)
// true

// generate Google Authenticator supported URL
totp.gaURL('handsome@totp.js', 'Totp.js')
// 'otpauth://totp/handsome@totp.js?issuer=Totp.js&secret=GAXGGYT2OU2DEOJR'

// OR
const totp2 = new TOTP(TOTP.base32.encode('your key'));
totp2.genOTP()

For Browser

<script src="./dist/totp.min.js" />
<script>
  var key = TOTP.randomKey();
  var totp = new TOTP(key);
  console.log(totp.genOTP());
</script>

Enjoy!

Lisence

© MIT

About

🎲TOTP(Time-based one-time password) generator, support for Google Authenticator

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published