1.0.0 • Published 4 years ago

simpleotp v1.0.0

Weekly downloads
31
License
MIT
Repository
github
Last release
4 years ago

Simple OTP

Time-based and HMAC-based One-Time Password libraryfor node.js

About

simpleotp is a simple :-) OTP library for node.js.

It provides an implementation of both rfc 4226 (HOTP) and rfc 6238 (TOTP).

Installation

npm install --save simpleotp

Usage

HOTP

Example

const otp = require('simpleotp');
const hotp = new otp.Hotp();

// generate a token
const token = hotp.createToken({secret:'12345678901234567890',counter:7});

// validate the token
const data = {token: token, secret:'12345678901234567890',counter: 7};
const valid = hotp.validate(data); //true

Configuration

Constructor options
OptionValueDescriptionDefault Value
algorithmsha1,sha256,sha512Algorithm to usesha1
num_digitsintegertoken length6
encodingasciiEncoding of the secretascii
Create Token options
OptionMandatoryValueDescriptionDefault value
secretystring typeShare secret to useN/A
counteryinteger typeThe counter seedN/A
algorithmn'sha1','sha256' or 'sha512'Algorithm to usesha1
num_digitsninteger typetoken length6
encodingn'ascii'Encoding of the secretascii
Validate token options
OptionMandatoryValueDescriptionDefault value
tokenystring typeThe original tokenN/A
secretystring typeShare secret to useN/A
counteryinteger typeThe counter seedN/A
algorithmn'sha1','sha256' or 'sha512'Algorithm to usesha1
num_digitsninteger typetoken length6
encodingn'ascii'Encoding of the secretascii

TOTP

Example

const otp = require('simpleotp');
const totp = new otp.Totp();

// generate the token
const token = totp.createToken({secret:'12345678901234567890',seconds :Date.now()/1000});

// validate the token
const data = {token: token, secret:'12345678901234567890',seconds :Date.now()/1000}
const valid = totp.validate(data)
console.log(valid); // true

Configuration

Constructor options
OptionValueDescriptionDefault value
algorithm'sha1','sha256' or 'sha512'Algorithm to usesha1
num_digitsintegertoken length6
encodingasciiEncoding of the secretascii
stepintegerNumber of the second the token is valid30
Create Token options
OptionMandatoryValueDescriptionDefault value
secretystring typeShare secret to useN/A
secondsyintegertime in seconds as counterDate.now()/1000
stepnintegerNumber of the second the token is valid30
algorithmn'sha1','sha256' or 'sha512'Algorithm to usesha1
num_digitsninteger typetoken length6
encodingn'ascii'Encoding of the secretascii
Validate token options
OptionMandatoryValueDescriptionDefault value
tokenystring typeThe original tokenN/A
secretystring typeShare secret to useN/A
secondsYintegertime in seconds as counterDate.now()/1000
stepnintegerNumber of the second the token is valid30
algorithmn'sha1','sha256' or 'sha512'Algorithm to usesha1
num_digitsninteger typetoken length8
encodingn'ascii'Encoding of the secretascii

Tests

npm test

References

License

simpleotp is MIT licensed

1.0.0

4 years ago

0.7.7

4 years ago

0.7.6

6 years ago

0.7.5

6 years ago

0.7.4

6 years ago

0.7.3

6 years ago

0.7.1

6 years ago