How to Create a Login and Registration API in ASP.NET Core 10 Using JWT Authentication

In This Article
- Login & Registration API in ASP.NET Core 10, using Entity Framework Core, Password Hashing, and JWT Token Authentication.
- 1. Create a New ASP.NET Core 10 Web API Project
- 2. Create the Model
- 3. Create the DTO Model
- 4. Create the Authentication Controller (Simple Version)
- 5. Implement JWT Token Authentication
- 6. Connect the API to SQL Server Database
- DbContext File: MSIHRDbContext.cs
- Add Connection String in appsettings.json
- Program.cs – Configure Database
- 7. Run Migrations
- 8. Test Using Swagger
User authentication is one of the most essential features in any modern application. In this guide, we will walk through the complete process of creating a
Login & Registration API in ASP.NET Core 10, using Entity Framework Core, Password Hashing, and JWT Token Authentication.
- This tutorial covers:
- Creating a new ASP.NET Core 10 Web API project
- Setting up models and DTOs
- Creating authentication controllers
- Implementing JWT token generation
- Connecting to SQL Server
- Adding DbContext and migrations
- Using Service & IService layers for clean architecture
Let’s get started!
1. Create a New ASP.NET Core 10 Web API Project
Open the terminal and run: dotnet new webapi -n MSIHR This creates a new API project with Swagger enabled so you can easily test login and registration.
2. Create the Model
Create a new file User.cs inside the Models folder:
public class User {
public string Username { get; set; }
public string PasswordHash { get; set; } // used to store hashed password
} The password will not be stored directly. Instead, we will store a hashed version for security.
3. Create the DTO Model
Create a file UserDto.cs:


