Remove default PasswordValidator from Asp.Net Core

638 Views Asked by At

I've created my own PasswordValidator and add it to the IdentityBuilder by using services.AddIdentity<, >().AddPasswordValidator<>(). This adds my PasswordValidator on top of the default one, so the password will be checked by both. (not what I need).

How can I remove the default one?

1

There are 1 best solutions below

0
On BEST ANSWER

AddIdentity only adds the default PasswordValidator implementation if one hasn't already been registered. Because of this, you can add your custom implementation before calling AddIdentity:

services.AddScoped<IPasswordValidator<YourUser>, YourPasswordValidator>();
services.AddIdentity<YourUser, YourRole>(...);

In this case, only YourPasswordValidator gets registered.