Reputation: 452
I'm using Identity in an ASP.NET Core Web API application and want to use custom Identity options. I pass them in the Startup.cs
when registering Identity like this:
Action<IdentityOptions> configureOptions = options =>
{
options.Password.RequireDigit = false;
options.Password.RequiredLength = 4;
options.Password.RequireLowercase = false;
options.Password.RequireUppercase = false;
options.Password.RequireNonAlphanumeric = false;
options.SignIn.RequireConfirmedAccount = true;
options.SignIn.RequireConfirmedEmail = true;
};
services
.AddIdentityCore<ApplicationUser>(configureOptions)
.AddDefaultTokenProviders()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddErrorDescriber<CustomIdentityErrorDescriber>();
But these options doesn't change anything.
For example when I set passwords required minimum length to 4 and add a user's password with the length of 5 I get an IdentityError which says that the minimum length is 8.
That seems strange for me because the documentations of Identity states that the default value is 6?
So where does the 8 come from and why isn't it 4 as I configured it?
Upvotes: 0
Views: 870
Reputation: 7190
In fact, you have successfully configured the password length.
Since the default password length in Identity is 6, if you set it to 4, the verification will not pass.
You can find your login model in the following places:
You can see the InputModel
here(change the MinimumLength of password).
public class InputModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
//You can change the MinimumLength to 4.
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 4)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
I don't know why your default length is 8. Maybe you have modified it before.
Update:Do my following steps,and then find the InputModel
.
Upvotes: 1