1

1- start Visual studio 2013

2- create a project using the default MVC template that Microsoft provides.

3- Run the app and go to http://localhost:2618/Account/Register

4- enter an email address in the form

5- in the password fields enter: 12345678

6- Press Register button

You will see an this error message after form-post-back:

Passwords must have at least one non letter or digit character. Passwords must have at least one lowercase ('a'-'z'). Passwords must have at least one uppercase ('A'-'Z').

Where and how can I customize this message? I tried using data annotations but couldn't find a solution for it. Please give me specific details. I couldn't find an answer after a lot of searching for it even in the stackoverflow.

Thanks

******************** Note ************

The error message is different than the one which is available in AccountViewModels.cs file for the password field:

public class RegisterViewModel
{
    [Required]
    [EmailAddress]
    [Display(Name = "Email")]
    public string Email { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [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; }
}
acman123
  • 239
  • 3
  • 13

1 Answers1

0

To customize the datatype error messages you need to install the localized NuGet packages for AspNet.Identity.Core for each of the languages you want to support.

E.g. for German

Install-Package Microsoft.AspNet.Identity.Core.de

Note that the localized packages only exist for a few languages.

If you need other languages than the supported ones you will have to do some kind of hack. Have a look at the following, which includes a suggested workaround from one of the developers on the ASP.NET team: Asp.Net Identity Localization PublicKeyToken

Guilherme Holtz
  • 474
  • 6
  • 19