GithubHelp home page GithubHelp logo

sylonzero / node-pin Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 98 KB

Secure OTP Generation for Email Verification and More

Home Page: https://sylonzero.github.io/node-pin/

License: MIT License

JavaScript 100.00%

node-pin's Introduction

node-pin: Secure OTP Generation for Email Verification and More

The node-pin module offers a robust and secure solution for generating One-Time Passwords (OTPs), tailored specifically for authentication processes such as email verification. Built with security and ease of integration in mind, this library leverages Node.js's cryptographic modules to produce unpredictable and secure PINs, suitable for a wide array of verification and authentication scenarios.

Random Pin Generator

Features:

  • Secure Random PIN Generation: Utilizes Node.js's crypto module to ensure each PIN is cryptographically secure, making them ideal for sensitive authentication tasks.
  • Flexible Length Configuration: Generate PINs of any length between 1 and 50 digits, allowing for customization based on the security requirements of your application.
  • Promise-based API: Designed with modern asynchronous patterns in mind, node-pin supports both callback and Promise-based workflows, ensuring seamless integration into contemporary Node.js applications.
  • Simplified Integration: With minimal setup required, integrating node-pin into your project is straightforward, enabling you to add OTP generation functionality quickly and efficiently.
  • Versatile Use Cases: While optimized for email verification, the node-pin module can be easily adapted for SMS verification, two-factor authentication (2FA), and other scenarios where OTPs are essential.

Getting Started:

To begin using node-pin in your project, simply install the package using npm:

npm install node-pin --save

Then, generate a PIN by specifying the desired length:

const { RandomPinGenerator } = require('node-pin');

// Generate a 20-digit PIN
RandomPinGenerator.generate(20).then(pin => {
  console.log(`Generated PIN: ${pin}`);
}).catch(err => {
  console.error(err);
});

Callback example:

const { RandomPinGenerator } = require('node-pin');

// Generate a 6-digit PIN using the callback method
RandomPinGenerator.generateWithCallback(6, (err, pin) => {
    if (err) {
        console.error("An error occurred:", err);
        return;
    }
    console.log(`Generated PIN: ${pin}`);
});

SeededRandomGenerator

Provides a seeded random number generator capable of producing a consistent sequence of pseudo-random numbers, bytes, and hex strings based on a provided seed. This is particularly useful for scenarios requiring reproducible results.

Features

  • Generate random bytes with a given size.
  • Produce random hex strings.
  • Generate random numbers within a specified range.

Usage

Creating an instance and generating seeded random data:

const { SeededRandomGenerator } = require('node-pin');
const generator = new SeededRandomGenerator('my-seed');

// Generate random bytes
const bytes = generator.generateRandomBytes(10);
console.log(bytes);

// Generate a random hex string
const hexString = generator.getRandomHex(4);
console.log(hexString);

// Generate a random number within a range
const randomNumber = generator.getRandomNumber(1, 100);
console.log(randomNumber);

node-pin's People

Contributors

sylonzero avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.