Skip to content

3raffat/BareMinimum2FAWithIdentity

Repository files navigation

BareMinimum2FAWithIdentity

License: MIT

A minimal ASP.NET Core project demonstrating Two-Factor Authentication (2FA) using Email with Identity.
Perfect for learning or as a starting point for more advanced authentication flows.


Features

  • User registration
  • Email confirmation for first login
  • Two-Factor Authentication (2FA) via email
  • Simple and minimal setup with ASP.NET Core Identity

Requirements

  • .NET 7 or later
  • PostgreSQL database (or any EF Core compatible database)
  • SMTP server (for sending verification codes, e.g., MailKit)

Getting Started

  1. Clone the repository
git clone https://github.com/3raffat/BareMinimum2FAWithIdentity.git
  1. Configure Database and Email

Edit appsettings.Development.json:

{
  }
  "ConnectionStrings": {
    "DefaultConnection": ""
  },
  "JwtSettings": {
    "Secret": "",
    "TokenExpirationInMinutes": 0,
    "Issuer": "",
    "Audience": ""
  },

  "EmailSettings": {
    "From": "",
    "SmtpHost": "",
    "Port": 0,
    "Username": "",
    "Password": ""
  }
}

3.Install NuGet Packages

dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCore
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
dotnet add package MailKit

4.Run Migrations

dotnet ef database update

5.Run the Application

dotnet run

How It Works

1.User Registration

Users sign up with email and password. A confirmation email is sent for first login.

2.Email Confirmation

Users confirm their account by clicking the link or entering the code.

3.Two-Factor Authentication (2FA)

After confirmation, login requires a 2FA code sent to email.

4.Subsequent Logins

Verified users can log in normally with 2FA.


Notes

Bare minimum example: only supports email-based 2FA.

No QR codes or Authenticator apps included.

Can be extended to SMS or app-based 2FA.

Using PostgreSQL instead of SQL Server, ensure Npgsql provider is installed.

About

Minimal ASP.NET Core project demonstrating Email-based 2FA with Identity and PostgreSQL.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors