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
