liveBook · Manning

PasswordOptions

As explained in Pro ASP.NET Core 7, Tenth Edition

PasswordOptions is the ASP.NET Core Identity options class containing configuration for password validation requirements.

PasswordOptions configures ASP.NET Core Identity’s password validation policy. IdentityOptions exposes it through the Password property, connecting application startup configuration to account-creation checks. section 38.3.3

Configure these requirements with the options pattern:

  • RequiredLength sets the minimum password length. section 38.3.3
  • RequireNonAlphanumeric requires a character that is neither a letter nor a digit. section 38.3.3
  • RequireLowercase, RequireUppercase, and RequireDigit enforce lowercase, uppercase, and numeric characters. section 38.3.3

Configure a demonstration policy

Register IdentityOptions in Program.cs, set RequiredLength to 6, and disable the other constraints. Restart the application, open /users/create, and submit the password "secret"; the password is then accepted. section 38.3.3

Listing 38.14 Changing validation in the Program.cs file in the Advanced project
...
builder.Services.Configure<IdentityOptions>(opts => {
    opts.Password.RequiredLength = 6;
    opts.Password.RequireNonAlphanumeric = false;
    opts.Password.RequireLowercase = false;
    opts.Password.RequireUppercase = false;
    opts.Password.RequireDigit = false;
    opts.User.RequireUniqueEmail = true;
    opts.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyz";
});
...

Inspect the complete Program.cs configuration, including the PasswordOptions assignments and related user-validation settings. section 38.3.3

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Defines five requirement properties and demonstrates startup configuration, without descending into validator implementation internals.
Examples
Uses the /users/create form with Alice’s password "secret" before and after changing the validation policy.
What it assumes
Assumes ASP.NET Core Identity registration and introduces password policy configuration through IdentityOptions.
What you can do after
Configure it via IdentityOptions in Program.cs and verify acceptance or validation errors through the user-creation form.
How it connects
Connects IdentityOptions, the options pattern, user creation, and password validation errors.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.