Configuring Identity

With Identity in place, we can start to configure the settings of the library to meet our authentication requirements. The first place to start with configuring Identity to fit the needs of the project is in Program.cs.

Program.cs

Now that we are getting to configure our user, let’s check out the code in Program.cs. Earlier you may have added the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
builder.Services.AddDefaultIdentity<IdentityUser>
(options =>
{
   options.SignIn.RequireConfirmedAccount = true;
   options.Password.RequireDigit = false;
   options.Password.RequiredLength = 10;
   options.Password.RequireNonAlphanumeric = false;
   options.Password.RequireUppercase = true;
   options.Password.RequireLowercase = false;
}).AddEntityFrameworkStores<EventDbContext>();

This code is dictating the settings for account creation. Right now, for a user to create an account, they have to have the following:

  1. They have to click a link to confirm their account.
  2. Their password has to be more than 10 characters long.
  3. Their password has to include an uppercase letter(s).
  4. Their password does not have to include a number.
  5. Their password does not have to include a special character such as a question mark.
  6. Their password does not have to include lowercase letters.

These are just some basic requirements that can be changed to suit the needs of your application. For a full list of the default settings for users’ passwords and how we can change those settings, check out the documentation .

In Program.cs, we can also configure cookie settings, password hashers, user validation requirements, sign in settings and more.

Additional Customizations

As you learn more about what Identity can do, you may find yourself wanting to customize it more and more to suit your needs! Here are some examples of what you can do with it.

  1. Customize user information
  2. Customize user roles
  3. Customize the UI
  4. Add new settings to user passwords
  5. Change the default settings around user sign-in
Note

If you want to customize user data, it is best to do so when initially scaffolding the app. IdentityUser has a number of properties that are important and relevant to storing user data. However, when you read through the requirements you may notice that you need additional properties, such as the user’s first and last name. If you want to add custom properties, check out this article from Microsoft.