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

nitro-2fa-auth

v1.0.2

Published

Nitro is 2FA modele with words

Downloads

18

Readme

Nitro 2FA Authentication

Nitro 2FA is a Two-Factor Authentication system that uses word transformations for enhanced security. This project provides a set of functions to manage word sources and perform authentication checks.

Table of Contents

Prerequisites

Before you start, make sure you have the following installed:

  • Node.js and npm

Installation

  1. Clone this repository:

    git clone https://github.com/iamrosada/nitro-2fa.git
  2. Navigate to the project directory:

    cd nitro-2fa
  3. Install the required packages:

    npm install

Usage

Choose Word Source

The chooseWordSource function allows you to select the word source based on your configuration.

const sourceConfig = {
  sourceType: "file",
  userWords: "youruserwords",
  userPassword: "yourpassword",
};

chooseWordSource(sourceConfig)
  .then((result) => {
    console.log("Words Array:", result.wordsArray);
    console.log("Encrypted Data:", result.encryptedData);
  })
  .catch((error) => {
    console.error("Error:", error);
  });

Perform Nitro 2FA Authentication Check

The createNitro2FAContext function creates a context for authentication checks.

const context = createNitro2FAContext();

const words = ["word1", "word2", "word3"];
const userAnswer = "youranswer";

const verificationResult = await context.nitro2FA(words, userAnswer);

if (verificationResult.status === "Correct") {
  console.log("Authentication successful!");
} else {
  console.log("Authentication failed. New question:", verificationResult.newQuestion);
}

Create Nitro 2FA Context

The createNitro2FAContext function creates a context for the Nitro 2FA system, allowing you to retrieve word transformations and verify user answers.

import { createNitro2FAContext } from 'nitro-2fa-auth';

const myContext = createNitro2FAContext();

const transformationInfo = myContext.displayTransformationInfo();
console.log(transformationInfo);

const userAnswer = 'user_answer_here';
const result = myContext.nitro2FA(wordsArray, userAnswer);
console.log(result);

Example with REST API, Nitro 2FA Context

import bodyParser from 'body-parser';
import { chooseWordSource, createNitro2FAContext } from 'nitro-2fa-auth';
import express, { Request, Response } from 'express';


const app = express();
const port = 3000;

app.use(bodyParser.json());

let userPassword = "user_password_here"; 

const myContext = createNitro2FAContext();
let wordsArrayFor2FA: string[] = []; 

app.get('/2fa', async (req: Request, res: Response) => {
  try {
    const words = await chooseWordSource({ sourceType: 'file', userPassword: userPassword });

    wordsArrayFor2FA = words.wordsArray;

    res.json({ message: words.wordsArray, keySaveIntoDatabase: words.encryptedData });
  } catch (error) {
    console.error("Error:", error);
    res.status(500).json({ error: "Internal server error" });
  }
});


app.get('/passwordReset', (req: Request, res: Response) => {
  const transformationInfo = myContext.displayTransformationInfo();
  res.json({ transformationInfo });
});

app.post('/checkAnswer', async (req: Request, res: Response) => {
  try {
    const userAnswer = req.body.user_answer;

    const result = await myContext.nitro2FA(wordsArrayFor2FA, userAnswer);

    res.json(result); 
  } catch (error) {
    console.error("Error:", error);
    res.status(500).json({ error: "Internal server error" });
  }
});

app.listen(port, () => {
  console.log(`Server is listening on port ${port}`);
});

Code Structure

The project's code is organized as follows:

  • nitroEncryption.js: Encryption and decryption functions.
  • readWordsFromFile.js: Function to read words from a file.
  • transformWord.js: Function for transforming words.
  • getRandomTransformation.js: Function to get a random transformation.
  • provideUserWords.js: Function to provide user-specific words.

Replace placeholders like 'your_password_here' and 'user_answer_here' with actual values.

Contributing

Contributions to the Nitro 2FA project are welcome! You can contribute by submitting issues, feature requests, or pull requests.

If you want to contribute to this project, follow these steps:

  1. Fork the project.
  2. Create a new branch for your feature or fix.
  3. Commit your changes.
  4. Push to your fork.
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Contact

If you have any questions or need assistance, you can reach out to Luis de Agua Rosada.