ASP.NET MVC password validator doesn't warn about some mandatory requirements on client side?

Csaba Toth

I'm using ASP.NET MVC5 which has unobtrusive validator hooked up for the client side validation out of the box. I set up my IdentityConfig.cs this way:

manager.PasswordValidator = new PasswordValidator
{
    RequiredLength = 8,
    RequireNonLetterOrDigit = true,
    RequireDigit = true,
    RequireLowercase = true,
    RequireUppercase = true,
};

When the password is not too long client side validation warns properly. But it doesn't seem to do validation about the rest of the criteria (at least one digit, at least on upper case letter, at least one lower case letter, not even speak about the special characters). In my use-case it'd be important to have these on client side.

What's the best way to enable these extra checks? Should I setup my own non-obtrusive validation rules? How would that interfere with the unobtrusive validation?

user3559349

Add a RegularExpressionAttribute to your property. Based on Srinivas' answer to Regex for Password Must be contain at least 8 characters, least 1 number and both lower and uppercase letters and special characters, the following should suit your rules

[RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}", ErrorMessage = "...")]
public string Password { get; set; }

and in the view

@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(m =>m.Password)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Client side validation for custom validator asp.net MVC 4

ASP.NET MVC Fluent Validation doesn't work on the client side for view model's property which is another type of class

ASP.NET required validator change from client side

ASP.Net MVC Client Side and Server Side Calculations

Why doesn't ASP.net RadioButtonList onchange client side event trigger?

Adding client side validation failures to ASP.NET MVC ModelState

Configure culture for client side validation in ASP.NET Core MVC

Does ASP.NET MVC denies use of client side MVVM?

Conditional client side validation in ASP.NET MVC Core 3.1

Client side validation in asp.net mvc3

Asp.net MVC 4 Client Side Validation Not Work

ASP.NET MVC customError page doesn't get displayed for some of the 400 errors

Some basic questions about Routing in ASP.NET MVC

Why doesn't Java warn about a == "something"?

How to make RequiredIf Client-side and server-side validation in ASP.NET Core 3.1 MVC?

FormGroup confirm password validator doesn't work

The jquery ajax doesn't work (the server side is ASP.net)

Can't verify password on client side

validator is undefined in asp.net mvc

ASP.NET MVC Custom Validator not triggering

VueJS: Is there an easy way to validate email and password on client side based on the server side's validator?

How to print multiple excel sheet on client side printer in asp.net mvc?

Render ASP.NET MVC partial view based on a condition on client side

How to use Globalize.js to configure culture for client side validation in ASP.NET Core MVC

ASP.Net Core MVC - Run client side script/function after form submit data success

ASP.Net Core MVC - Client-side validation for custom attribute

How to check if user already exists on client-side in ASP.NET MVC 5?

ASP.NET MVC ValidationAttribute causes invalid client side validation rules

How to stop ajax spinner on ASP.NET MVC register form if client side validation fails