This project is a sample implementation of Multi-Factor Authentication (MFA) in a .NET Core 8 application. It demonstrates how to enhance the security of a web application by integrating MFA, requiring users to verify their identity using both their password and an additional verification code from an authenticator app, such as Google Authenticator or Authy. This project uses SQLite as the database, making it simple to set up and run locally.
- Two-Factor Authentication (2FA): Users are prompted to enable two-factor authentication for added security. Once enabled, they need to enter a code from an authenticator app at login.
- QR Code Generation: Utilizes the QRCoder library to generate QR codes for easy setup in authenticator apps.
- SQLite Database: A lightweight, file-based database for easy configuration and testing.
- ASP.NET Core Identity: Uses ASP.NET Core Identity for user management, including user registration, login, and MFA setup.
Ensure you have the following installed on your system:
- .NET Core SDK 8 (or compatible version specified by the project)
- SQLite if using SQLite as the database
- (Optional) JetBrains Rider or any preferred .NET Core IDE
Clone the project repository to your local machine using the following command:
git clone https://github.com/DiogenesPolanco/MfaDiogenes.git
cd MfaDiogenes
Make sure your database is set up correctly. This project is configured to use SQLite by default. You can modify the database connection string in appsettings.json
if needed:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=MfaDiogenesDb.db"
}
}
To ensure your database schema is up to date, apply any pending migrations:
dotnet ef database update
Note: Make sure that the
dotnet-ef
CLI tool is installed. You can install it globally with:dotnet tool install --global dotnet-ef
To start the application, use the following command:
dotnet run
This will start the application on the default port. You should see output indicating that the app is running, such as:
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
Once the application is running, open a web browser and navigate to:
http://localhost:5000
To publish and build the application for production:
dotnet publish --configuration Release
This will output the files to the ./bin/Release/netcoreapp8.0/publish
directory (adjust path based on your .NET Core version).
- MFA (Multi-Factor Authentication): If MFA is enabled in this project, you may need to scan a QR code and use an authenticator app during the login process.
- Environment Variables: Set any required environment variables for sensitive information, like API keys, in the
.env
file or in your system’s environment settings.