AspNet.Identity PasswordValidator

M J 661 Reputation points
2022-09-14T17:09:02.767+00:00

I have both English and Spanish version of the website. Is there a way to have the validation message appear in Spanish when on the Spanish Version?

I have altered the RegisterViewModel

public class RegisterViewModel  
{  
    [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "FirstNameRequired")]  
    [Display(Name = "FirstName", ResourceType = typeof(Registration))]  
    [StringLength(30, ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "FirstNameLength")]  
    public string FirstName { get; set; }  
  
    [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "LastNameRequired")]  
    [Display(Name = "LastName", ResourceType = typeof(Registration))]  
    [StringLength(50, ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "LastNameLength")]  
    public string LastName { get; set; }  
  
    [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "EmailRequired")]  
    [EmailAddress]  
    [Display(Name = "Email", ResourceType = typeof(Registration))]  
    public string Email { get; set; }  
  
    [StringLength(100, ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "PasswordMinimum", MinimumLength = 8)]  
    [DataType(DataType.Password)]  
    [Display(Name = "Password", ResourceType = typeof(Registration))]  
    [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "PasswordRequired")]  
    public string Password { get; set; }  
  
    [DataType(DataType.Password)]  
    [Display(Name = "PasswordConfirm", ResourceType = typeof(Registration))]  
    [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "PasswordConfirmRequired")]  
    [Compare("Password", ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "Compare")]  
    public string ConfirmPassword { get; set; }  
  
    [Display(Name = "Telephone", ResourceType = typeof(Registration)), Phone]  
    [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "TelephoneRequired")]  
    [DataType(DataType.PhoneNumber)]  
    public string PhoneNumber { get; set; }  
   
    public string CaptchaCode { get; set; }  
}  

but don't know how to change the message when it is missing a requirement such as

Passwords must have at least one uppercase ('A'-'Z')

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,243 questions
0 comments No comments
{count} votes

Accepted answer
  1. XuDong Peng-MSFT 10,096 Reputation points Microsoft Vendor
    2022-09-15T06:53:31.04+00:00

    Hi @M J ,

    Based on your description, if you just want to show error messages in Spanish, you can try the following steps:

    1. Install the identity localized package in Package Manager Console : PM> Install-Package Microsoft.AspNet.Identity.Core.es.
    2. Add the configuration code to the Web.config: <system.web>
      <globalization culture="es-ES" uiCulture="es" />
      </system.web>
      Then you can check the validation message like this:

    241270-image.png

    If I misunderstood anything about your requirement, just let me know.

    Best regards,
    Xudong Peng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful