Notp

Node One Time Password library, supports HOTP, TOTP and works with Google Authenticator
Alternatives To Notp
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Aegis6,226
2 days ago69gpl-3.0Java
A free, secure and open source app for Android to manage your 2-step verification tokens.
Speakeasy2,63354523215 days ago7January 27, 201664mitJavaScript
**NOT MAINTAINED** Two-factor authentication for Node.js. One-time passcode generator (HOTP/TOTP) with support for Google Authenticator.
Authenticatorpro1,726
2 days ago56gpl-3.0C#
📱 Two-Factor Authentication (2FA) client for Android + Wear OS
Google Authenticator Libpam1,584
7 days ago1March 03, 202160apache-2.0C
Otplib1,5581722439 months ago55January 24, 202078mitTypeScript
:key: One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator
Rotp1,5242,52763a month ago38December 13, 20223mitRuby
Ruby One Time Password library
Googleauth9606814a year ago16April 04, 202011bsd-3-clauseJava
Google Authenticator Server side code
Otpauth663112120 hours ago89November 10, 20226mitJavaScript
One Time Password (HOTP/TOTP) library for Node.js, Deno, Bun and browsers.
Notp662169654 months ago5October 14, 201422mitJavaScript
Node One Time Password library, supports HOTP, TOTP and works with Google Authenticator
Auth587
7 days ago27gpl-3.0Dart
ente Auth – store your 2FA secrets
Alternatives To Notp
Select To Compare


Alternative Project Comparisons
Readme

Build Status

Node One Time Password library

Simple to use, fast, and with zero dependencies. The Node One Time Password library is fully compliant with HOTP (counter based one time passwords) and TOTP (time based one time passwords). It can be used in conjunction with the Google Authenticator which has free apps for iOS, Android and BlackBerry.

Installation

npm install notp

Usage

var notp = require('notp');

//.... some initial login code, that receives the user details and TOTP / HOTP token

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

// Check TOTP is correct (HOTP if hotp pass type)
var login = notp.totp.verify(token, key);

// invalid token if login is null
if (!login) {
    return console.log('Token invalid');
}

// valid token
console.log('Token valid, sync value is %s', login.delta);

Google Authenticator

Google authenticator requires that keys be base32 encoded before being used. This includes manual entry into the app as well as preparing a QR code URI.

To base32 encode a utf8 key you can use the thirty-two module.

var base32 = require('thirty-two');

var key = 'secret key for the user';

// encoded will be the secret key, base32 encoded
var encoded = base32.encode(key);

// Google authenticator doesn't like equal signs
var encodedForGoogle = encoded.toString().replace(/=/g,'');

// to create a URI for a qr code (change totp to hotp if using hotp)
var uri = 'otpauth://totp/somelabel?secret=' + encodedForGoogle;

Note: If your label has spaces or other invalid uri characters you will need to encode it accordingly using encodeURIComponent More details about the uri key format can be found on the google auth wiki

API

hotp.verify(token, key, opt)

Check a counter based one time password for validity.

Returns null if token is not valid for given key and options.

Returns an object {delta: #} if the token is valid. delta is the count skew between client and server.

opt

window

The allowable margin for the counter. The function will check window codes in the future against the provided token. i.e. if window = 100 and counter = 5 all tokens between 5 and 105 will be checked against the supplied token Default - 50

counter

Counter value. This should be stored by the application on a per user basis. It is up to the application to track and increment this value as needed. It is also up to the application to increment this value if there is a skew between the client and server (delta)

totp.verify(token, key, opt)

Check a time based one time password for validity

Returns null if token is not valid for given key and options.

Returns an object {delta: #} if the token is valid. delta is the count skew between client and server.

opt

window

The allowable margin for the counter. The function will check window codes in the future against the provided token. i.e. if window = 5 and counter = 1000 all tokens between 995 and 1005 will be checked against the supplied token Default - 6

time

The time step of the counter. This must be the same for every request and is used to calculate C. Default - 30

hotp.gen(key, opt)

Return a counter based one time password

opt

counter

Counter value. This should be stored by the application, must be user specific, and be incremented for each request.

totp.gen(key, opt)

Return a time based one time password

opt

time

The time step of the counter. This must be the same for every request and is used to calculate C. Default - 30

Migrating from 1.x to 2.x

Removed

The encBase32 and decBase32 methods have been removed. If you wish to encode/decode base32 you should install a module to do so. We recommend the thirty-two npm module.

Changed

All of the APIs have been changed to return values directly instead of using callbacks. This reflects the fact that the functions are actually synchronous and perform no I/O.

Some of the required arguments to the functions have also been removed from the args parameter and are passed as separate function parameters. See the above API docs for details.

  • notp.checkHOTP(args, err, cb) -> notp.hotp.verify(token, key, opt)
  • notp.checkTOTP(args, err, cb) -> notp.totp.verify(token, key, opt)
  • notp.getHOTP(args, err, cb) -> notp.gotp.gen(key, opt)
  • notp.getTOTP(args, err, cb) -> notp.totp.gen(key, opt)

Args

The argument names have also changed to better describe the purpose of the argument.

  • K -> no longer in args/opt but passed directly as a function argument
  • P -> no longer in args/opt but passed directly as a function argument
  • W -> window
  • C -> counter
  • T -> time
Popular Authenticator Projects
Popular Totp Projects
Popular Security Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Javascript
Token
Password
Time
Counter
Authenticator
Totp
Hotp