{"id":17966253,"url":"https://github.com/iamrosada/nitro-2fa","last_synced_at":"2025-04-03T20:40:29.735Z","repository":{"id":204656789,"uuid":"712361576","full_name":"iamrosada/nitro-2fa","owner":"iamrosada","description":"Npm Package for Two factor authentication encryption with 12 words","archived":false,"fork":false,"pushed_at":"2023-11-11T14:02:34.000Z","size":227,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-09T23:34:17.680Z","etag":null,"topics":["authentication","nodejs","npm-package","pishing","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nitro-2fa-auth","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iamrosada.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-31T10:15:46.000Z","updated_at":"2023-11-11T14:05:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"28a7d94e-ac1b-4bd0-b067-7a9c5a31f4c1","html_url":"https://github.com/iamrosada/nitro-2fa","commit_stats":null,"previous_names":["iamrosada/nitro-2fa"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamrosada%2Fnitro-2fa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamrosada%2Fnitro-2fa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamrosada%2Fnitro-2fa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamrosada%2Fnitro-2fa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iamrosada","download_url":"https://codeload.github.com/iamrosada/nitro-2fa/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247078756,"owners_count":20879948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","nodejs","npm-package","pishing","typescript"],"created_at":"2024-10-29T13:08:39.546Z","updated_at":"2025-04-03T20:40:29.711Z","avatar_url":"https://github.com/iamrosada.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Nitro 2FA Authentication\n\nNitro 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.\n\n\n## Table of Contents\n\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Code Structure](#code-structure)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Prerequisites\n\nBefore you start, make sure you have the following installed:\n\n- Node.js and npm\n\n## Installation\n\n1. Clone this repository:\n\n   ```bash\n   git clone https://github.com/iamrosada/nitro-2fa.git\n   ```\n\n2. Navigate to the project directory:\n\n   ```bash\n   cd nitro-2fa\n   ```\n\n3. Install the required packages:\n\n   ```bash\n   npm install\n   ```\n\n\n### Usage\n\n#### Choose Word Source\n\nThe `chooseWordSource` function allows you to select the word source based on your configuration.\n\n```javascript\nconst sourceConfig = {\n  sourceType: \"file\",\n  userWords: \"youruserwords\",\n  userPassword: \"yourpassword\",\n};\n\nchooseWordSource(sourceConfig)\n  .then((result) =\u003e {\n    console.log(\"Words Array:\", result.wordsArray);\n    console.log(\"Encrypted Data:\", result.encryptedData);\n  })\n  .catch((error) =\u003e {\n    console.error(\"Error:\", error);\n  });\n```\n\n#### Perform Nitro 2FA Authentication Check\n\nThe `createNitro2FAContext` function creates a context for authentication checks.\n\n```javascript\nconst context = createNitro2FAContext();\n\nconst words = [\"word1\", \"word2\", \"word3\"];\nconst userAnswer = \"youranswer\";\n\nconst verificationResult = await context.nitro2FA(words, userAnswer);\n\nif (verificationResult.status === \"Correct\") {\n  console.log(\"Authentication successful!\");\n} else {\n  console.log(\"Authentication failed. New question:\", verificationResult.newQuestion);\n}\n```\n\n\n### Create Nitro 2FA Context\n\nThe `createNitro2FAContext` function creates a context for the Nitro 2FA system, allowing you to retrieve word transformations and verify user answers.\n\n```javascript\nimport { createNitro2FAContext } from 'nitro-2fa-auth';\n\nconst myContext = createNitro2FAContext();\n\nconst transformationInfo = myContext.displayTransformationInfo();\nconsole.log(transformationInfo);\n\nconst userAnswer = 'user_answer_here';\nconst result = myContext.nitro2FA(wordsArray, userAnswer);\nconsole.log(result);\n```\n### Example with REST API, Nitro 2FA Context\n\n```typescript\nimport bodyParser from 'body-parser';\nimport { chooseWordSource, createNitro2FAContext } from 'nitro-2fa-auth';\nimport express, { Request, Response } from 'express';\n\n\nconst app = express();\nconst port = 3000;\n\napp.use(bodyParser.json());\n\nlet userPassword = \"user_password_here\"; \n\nconst myContext = createNitro2FAContext();\nlet wordsArrayFor2FA: string[] = []; \n\napp.get('/2fa', async (req: Request, res: Response) =\u003e {\n  try {\n    const words = await chooseWordSource({ sourceType: 'file', userPassword: userPassword });\n\n    wordsArrayFor2FA = words.wordsArray;\n\n    res.json({ message: words.wordsArray, keySaveIntoDatabase: words.encryptedData });\n  } catch (error) {\n    console.error(\"Error:\", error);\n    res.status(500).json({ error: \"Internal server error\" });\n  }\n});\n\n\napp.get('/passwordReset', (req: Request, res: Response) =\u003e {\n  const transformationInfo = myContext.displayTransformationInfo();\n  res.json({ transformationInfo });\n});\n\napp.post('/checkAnswer', async (req: Request, res: Response) =\u003e {\n  try {\n    const userAnswer = req.body.user_answer;\n\n    const result = await myContext.nitro2FA(wordsArrayFor2FA, userAnswer);\n\n    res.json(result); \n  } catch (error) {\n    console.error(\"Error:\", error);\n    res.status(500).json({ error: \"Internal server error\" });\n  }\n});\n\napp.listen(port, () =\u003e {\n  console.log(`Server is listening on port ${port}`);\n});\n\n```\n## Code Structure\n\nThe project's code is organized as follows:\n\n- `nitroEncryption.js`: Encryption and decryption functions.\n- `readWordsFromFile.js`: Function to read words from a file.\n- `transformWord.js`: Function for transforming words.\n- `getRandomTransformation.js`: Function to get a random transformation.\n- `provideUserWords.js`: Function to provide user-specific words.\n\n\n\nReplace placeholders like `'your_password_here'` and `'user_answer_here'` with actual values.\n\n\n\n\n## Contributing\n\nContributions to the Nitro 2FA project are welcome! You can contribute by submitting issues, feature requests, or pull requests.\n\nIf you want to contribute to this project, follow these steps:\n\n1. Fork the project.\n2. Create a new branch for your feature or fix.\n3. Commit your changes.\n4. Push to your fork.\n5. Open a pull request.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n\n## Contact\n\nIf you have any questions or need assistance, you can reach out to [Luis de Agua Rosada](mailto:luisrosa@mail.ru).\nYoutube link https://youtu.be/BfszqpTiyFc?si=CWBDWxBRT05eiUBy\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamrosada%2Fnitro-2fa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamrosada%2Fnitro-2fa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamrosada%2Fnitro-2fa/lists"}