1

I want to invalidate my password field if password strength is weak.

I am using "pstrength" method to calculate password strength.

Bar below password input box changes color as password strength increases.

I am using jQuery Validation plugin to validate rest of my form fields which is working fine.

I need to trigger error messages if password is weak , say if strength is less than 30 count(e.g. in fiddle) and strength bar color is yellow or green.

I have added fiddle for the same here

addMethod will add new validation method but actually i need to trigger error from external functionality "pStrength" when passwordStrength is lower than expected

I tried to call it as for e.g.

if(passwordStrength < 30){

            var $validator = jQuery("#registerForm").validate();
            $validator.showErrors("password strength is low");

        }

But no luck

Sparky
  • 98,165
  • 25
  • 199
  • 285
Mayank
  • 934
  • 1
  • 17
  • 37
  • This makes no sense. "external functionality"? You would put this external functionality into the `addMethod()` function and that would trigger your errors. – Sparky Jul 08 '14 at 15:01
  • You may not realize it, but you are asking how to create a custom rule for the jQuery Validate plugin. – Sparky Jul 08 '14 at 15:04

1 Answers1

1

I would recommend using addMethod to validate the password strength with checkPassword. So you can do something like this:

var options = {
    verdicts: ["Very Weak", "Weak", "Medium", "Strong", "Very Strong"],
    colors: ["#f00","#c06", "#f60","#3c0","#3f0"],
    scores: [10,15,30,40],
    minchar: 8
};
jQuery.validator.addMethod("passwordStrength", function(val, el, param) {
    return jQuery.fn.checkPassword(val, options) > param;
}, "password strength is too low");
Erik Sandberg
  • 486
  • 5
  • 14