npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@meiaentrada/otp-client

v1.0.1

Published

Módulo para geraçao de validacao token baseados em tempo(OTP)

Downloads

2

Readme

MEIA ENTRADA OTP

This is a simple library to implement features based on OTP (One-Time Password) algorithms, more specific TOTP algorithm. OTP algorithms are commonly used to implement two factor authentication (2FA). There are two algorithms: HOTP(HMAC-based One-Time Password) and TOTP(Time-Based One-Time Password):

  • HOTP This algorithm generates a otp code based in a secret, current timestamp and a event counter, see RFC 4226.
  • TOTP This algorithm generates the otp code based in a secret and current timestamp. see RFC 6238

To install

To install and save this dependencie in package.json:

npm i meiaentrada-otp --save

To simple install:

npm i meiaentrada-otp

Knowledge

  • secret: A unique key value per user to generate otp values; For example: "secret_of_client_01"

  • holder: A value to represent a people or entity that is using otp value like a client. For example: "bank_01"

  • issuer: A value to represent the website or enterprise that is generating otp values to clients. For example: "bank_client_01"

  • otp value: A positive number with 6 characters. For example: "123456"

Methods

generateKey() Generates a 32-character (160-bit) base32 key

generateOtpURI(secret, holder, issuer) Generate a URI base on OTPAUTH protocol - for more info. There is only a exception, the holder information is present on the URI params.

isValidTokenOTP(secret, otpValue) Validates a time-based token within a +/- 30 second (90 seconds) window. Return true or false in according with secret, current timestamp and otp value.

generateTokenOTP(secret) Generates a 6-digit (20-bit) decimal time-based token

Usage

const otp = require('meiaentrada-otp');

const secret = otp.generateKey();
console.log(secret); // "igxo jj5n gpuj gv4c lotw ve7d tmlu xftb"

const holder = 'user_01';
const issuer = 'enterprise_01';

const uri = otp.generateOtpURI(secret, holder, issuer);
console.log(uri); // otpauth://totp/enterprise_01:user_01?secret=7MEYUZ52337HOOKX25GE3RVIMQ6MJK4O&issuer=enterprise_01&algorithm=SHA1&digits=6&period=30&holder=user_01

const otpCode = otp.generateTokenOTP(secret);
console.log(otpCode); // 774729

let isValidToken = otp.isValidTokenOTP(secret, otpCode);
console.log(isValidToken); // true

isValidToken = otp.isValidTokenOTP('wrong-secret', otpCode);
console.log(isValidToken); // false