This is a simple Node.js and Express application that demonstrates two-factor authentication (2FA) using Speakeasy, MongoDB for user storage, and QR codes for setup.
Before running the application, make sure you have the following installed:
-
Clone the repository:
git clone https://github.com/yourusername/2fa-application.git
-
Install dependencies:
cd 2fa-application npm install
-
Start the application:
node index.js
The server will be running on http://localhost:3000.
- Open your browser and go to http://localhost:3000.
- Fill in the registration form to register a new user. The server will provide a QR code for 2FA setup.
- Use an authenticator app (e.g., Google Authenticator) to scan the QR code and generate OTPs.
- Fill in the verification form with your username and the OTP generated by the authenticator app to verify.
-
This is a basic example for sample backend purposes. In a production environment, additional security measures and considerations should be implemented.
-
Make sure to secure your MongoDB connection and handle errors more gracefully in a real-world scenario.
-
The application is configured to connect to a MongoDB database named
2fa-example
. Adjust the connection URI inindex.js
if needed.
This project is licensed under the MIT License - see the LICENSE file for details.