JavaScript One Time Password library, supports HOTP, TOTP and works with Google Authenticator • forked from https://github.com/guyht/notp
Go to file
AJ ONeal 31e53bb6ad Update 'README.md' 2017-11-20 16:58:12 +00:00
.gitignore browser fork 2015-10-22 21:22:21 -07:00
.travis.yml remove node v0.4.x support 2014-04-07 03:22:46 -07:00
LICENSE cleanup README 2012-06-03 18:01:30 -04:00
README.md Update 'README.md' 2017-11-20 16:58:12 +00:00
bower.json bump 2015-10-23 03:19:46 -07:00
index.js browser fork 2015-10-22 21:22:21 -07:00
package.json add thirty-two to dev-dependencies 2014-11-06 19:37:19 +08:00
sha1-hmac.js try/catch WebCrypto to forge 2015-10-23 03:19:41 -07:00
test.html browser fork 2015-10-22 21:22:21 -07:00
test.js browser fork 2015-10-22 21:22:21 -07:00

README.md

You might be in the wrong place

You probably want Authenticator.

Browser One Time Password library (JavaScript)

(aka botp / totp.js / hotp.js)

(forked from Node One Time Password)

Simple to use, fast, and with zero dependencies*. The Browser One Time Password library is fully compliant with HOTP (counter based one time passwords) and TOTP (time based one time passwords).

* requires forge for window.sha1Hmac shim in older browsers and es6-promise for ancient browsers.

It can be used in conjunction with the Authy, Google Authenticator, and Microsoft Authenticator, and GAuth which have free apps for iOS, Android, BlackBerry, OS X, Linux, Windows, and Chrome.

Browser One Time Password library, supports HOTP, TOTP and works with Google Authenticator • forked from https://github.com/guyht/notp

Installation

bower install botp

Usage

(function () {
'use strict';

var botp = window.botp;

// this might be used on account creation to create the QR code and verify the token in the browser.

var key = 'secret key for user... could be stored in DB'; // Uint8Array
var token = 'user supplied one time use token'; // 890123

// Check TOTP is correct (HOTP if hotp pass type)
botp.totp.verify(token, key).then(function (login) {
  // invalid token if login is null
  if (!login) {
    console.log('Token invalid');
    return;
  }
  
  // valid token
  console.log('Token valid, sync value is %s', login.delta);
});

}());

API

See https://github.com/guyht/notp#api

  • botp.totp.gen(keyByteArray) => (promise) tokenArray
  • botp.totp.verify(tokenByteArray, keyByteArray) => (promise) delta or null
  • botp.hotp.gen(keyByteArray) => (promise) tokenArray
  • botp.hotp.verify(tokenByteArray, keyByteArray) => (promise) delta or null