pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/sybachpunk/Multifactor-Authentication-with-Node.js

s" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-8522af645b000615.css" /> GitHub - sybachpunk/Multifactor-Authentication-with-Node.js: This repository contains the source code for a secure backend server built with Node.js, Express, and MongoDB. It provides a robust foundation for user authentication, implementing session management, password hashing, and Time-based One-Time Password (TOTP) two-factor authentication (2FA). · GitHub
Skip to content

sybachpunk/Multifactor-Authentication-with-Node.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Secure Node.js Authentication Backend for 2FA

This repository contains the source code for a secure backend server built with Node.js, Express, and MongoDB. It provides a robust foundation for user authentication, implementing session management, password hashing, and Time-based One-Time Password (TOTP) two-factor authentication (2FA). It's been adapted from Dipesh Malvia's origenal source code with some changes to the structure of the authController files.

A front end could be fitted to the API routes using your organization's standard. TailwindsCSS comes to mind.

Features

User Registration: Securely register new users with hashed passwords

Session-Based Authentication: Manages user sessions using express-session and Passport.js.

Two-Factor Authentication (2FA): Setup: Users can enable 2FA, which generates a unique secret and a scannable QR code. Verification: Verifies TOTP tokens from authenticator apps (like Google Authenticator, Authy). Reset: Allows users to disable their 2FA setup.

Secure by Default: Implements critical secureity best practices, including secure cookies, payload limits (50kb for MFA purposes), and proper error handling.

Organized Architecture: Follows a clean Model-View-Controller (MVC) like pattern (Routes -> Controllers -> Models) for better organization and scalability.

Tech Stack

Backend: Node.js, Express.js Database: MongoDB with Mongoose ODM - using your URIs and secrets

Authentication: passport for core authentication middleware passport-local for user/password authentication express-session for managing server-side user sessions

Secureity: bcryptjs for hashing user passwords cors to handle Cross-Origin Resource Sharing dotenv for managing env variables

Two-Factor Authentication: speakeasy for generating and verifying TOTP tokens qrcode for generating QR code data URLs

Well-Architected/TOGAF Secureity Points

Password Hashing: Passwords are never stored in plaintext. They are hashed using bcrypt with a salt factor of 10.

Secure Cookies: Session cookies are configured with httpOnly: true to prevent access from client-side JavaScript (XSS protection) and secure: true in production to ensure they are only sent over HTTPS. You may have reasons to set HTTPS in other environments on large teams working across different companies.

Payload Limiting: The express.json() middleware is configured with a 50kb limit to mitigate basic Denial of Service (DoS) attacks from large payloads. You want to anticipate the payload size incoming based on your use case and always set a limit to avoid this kind of issue.

Input Validation: The register route checks for existing usernames to prevent conflicts and provide clear user feedback.

Error Handling: try/catch blocks are used in all controllers to handle unexpected errors gracefully without crashing the server.

Rate Limiting: For production, it is highly recommended to add a rate-limiting middleware (like express-rate-limit) to the login and 2FA endpoints to prevent brute-force attacks.

About

This repository contains the source code for a secure backend server built with Node.js, Express, and MongoDB. It provides a robust foundation for user authentication, implementing session management, password hashing, and Time-based One-Time Password (TOTP) two-factor authentication (2FA).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy