iammukeshm/CleanArchitecture.WebApi

Error response occurred when try to give wrong password policy.

geekz-reno opened this issue · 1 comments

Describe the bug
Error occurred when register new account when try to give wrong password policy on identity

To Reproduce
add identityoptions to services.AddIdentity

opt.Password.RequireDigit = true;
opt.Password.RequireLowercase = true;
opt.Password.RequireNonAlphanumeric = false;
opt.Password.RequireUppercase = true;

when i try to give password adindaku, will return this response.

{
  "Succeeded": false,
  "Message": "System.Collections.Generic.List`1[Microsoft.AspNetCore.Identity.IdentityError]",
  "Errors": null,
  "Data": null
}

Expected behavior
will return correct validation message

{
  "Succeeded": false,
  "Message": "One or more validation failures have occurred.",
  "Errors": [
    "Passwords must have at least one digit ('0'-'9').",
    "Passwords must have at least one uppercase ('A'-'Z')."
  ],
  "Data": null
}

Desktop (please complete the following information):

  • OS: MacOS Catalina

Additional context
the problem with throw new ApiException($"{result.Errors}"); it has string constructor.
problem solve when i switch to throw new ValidationException(result.Errors.Select(x => x.Description)); and add another constructor on ValidationException.cs that accept IEnumerable<string> failures.

but i think is that are not acceptable solution because it always return error with header message
"Message": "One or more validation failures have occurred.", either that the exception come from IdentityError or database error.

Es correcto los errores porque espera una contraseña que tenga mayusculas y que tenga valores numéricos