Build a Secure OTP Authentication System with ASP.NET Core (.NET 10)

In This Article
- Overview
- Architecture & Authentication Flow
- Verify OTP & Login Flow
- Database Models
- ApplicationUser (ASP.NET Identity)
- DTOs (Data Transfer Objects)
- AuthController (ASP.NET Core .NET 10)
- Core Endpoints
- Configuration (ASP.NET Core 10)
- Program.cs (Highlights)
- Email OTP Service
- Security Features
- Testing Guide
- Swagger Testing
- Production Enhancements
In modern applications, passwordless authentication is becoming the preferred choice for both security and user experience. In this blog, we’ll walk through a complete OTP-based authentication system built with ASP.NET Core (.NET 10) that supports both traditional password login and email-based OTP login, powered by ASP.NET Core Identity and JWT tokens.
This implementation is production-ready, scalable, and follows industry best practices.
Overview
This authentication system enables users to log in securely using a One-Time Password (OTP) sent to their email. It also keeps traditional email/password login for backward compatibility. Key Highlights
- 6-digit OTP generation
- 10-minute OTP expiry
- One-time use (prevents replay attacks)
- JWT-based authentication (60-minute session)
- Role-based authorization support
- Secure HTML email templates
Supported Login Methods
- Email + Password
- Email + OTP (Passwordless Login)
Architecture & Authentication Flow
Send OTP Flow
- User submits email
- System validates the user
- Generates a random 6-digit OTP
- Stores OTP with expiry time in database
- Sends OTP via email
- Returns success response


