DEV Community

Cover image for Understanding ASP.NET Core Identity: A Guide to the Default Database Tables
davinceleecode
davinceleecode Subscriber

Posted on

Understanding ASP.NET Core Identity: A Guide to the Default Database Tables

When working with ASP.NET Core Identity, a set of default tables is automatically created to manage user authentication, roles, claims, and more. These tables are essential for implementing secure and flexible identity management in your application. Here's a breakdown of what each table does:

Core Tables

AspNetUsers
✔️ This table stores user-related data such as:

  • UserName
  • Email
  • PasswordHash
  • PhoneNumber
  • SecurityStamp, etc.

Think of it as the main user profile table.


AspNetRoles
✔️ Contains all the roles defined in your app (e.g., Admin, Moderator, Customer).

Each role is stored once and assigned a unique ID and name.


AspNetUserRoles
✔️ Represents the many-to-many relationship between users and roles.

If one user is both an Admin and a Moderator, this table will contain two entries for that user.


AspNetUserLogins
🔐 Stores information when a user logs in using an external login provider like:

  • Google
  • Facebook
  • Microsoft
  • Twitter, etc.

It includes the provider name, key, and associated user ID.


AspNetUserTokens

💾 Contains tokens related to a user such as:

  • Password reset tokens
  • Email confirmation tokens
  • Two-factor authentication tokens

This helps manage temporary access scenarios securely.


AspNetUserClaims
📄 Stores custom claims assigned to individual users.

For example:

  • SubscriptionLevel = Premium
  • Department = HR

These claims are typically used for fine-grained authorization.


AspNetRoleClaims

📄 Similar to user claims but tied to roles instead.

Example:
If the Admin role has a claim like Permission = CanDelete, then all users assigned the Admin role inherit that claim.


✅ ASP.NET Core Identity Default Tables Summary

Table Name Purpose
AspNetUsers Stores user account info like username, email, password hash, etc.
AspNetRoles Stores role definitions (e.g., Admin, User, Manager).
AspNetUserRoles Maps users to roles (many-to-many relationship).
AspNetUserLogins Stores login data from external providers (e.g., Google, Facebook).
AspNetUserTokens Stores tokens for things like password resets, email confirmations, etc.
AspNetUserClaims Stores custom claims assigned directly to users.
AspNetRoleClaims Stores claims assigned to roles (users get these claims via role membership).

If you found this helpful, consider supporting my work at ☕ Buy Me a Coffee.

Top comments (0)