开发者

jquery password strength script

开发者 https://www.devze.com 2023-02-27 04:22 出处:网络
I am looking for a very simple开发者_开发问答 password strength script. Something along the lines of

I am looking for a very simple开发者_开发问答 password strength script.

Something along the lines of

$('input[type=password]').pstrength({
   min-length: 5,
   callback: function(value){
      //you can do whatever you want with the value here
   }
});

So I don't want a progress bar, or anything visual at all.

Is there anything out there like this?


try

var strength = 1;
var arr = [/{5,}/, /[a-z]+/, /[0-9]+/, /[A-Z]+/];
jQuery.each(arr, function(i, regexp) {
  if(this.value.match(regexp))
     strength++;
}

Read this article

jQuery password strength checker


Strength of a password should be checked on behalf of several parameters like the presence of special characters and numbers, length of the password etc.

I have found the below tutorial with nice demo:

http://tinytute.com/2014/06/03/animated-password-strength-checker-quick-easy/

The jQuery code block:

    var passWord = $("#textBox").val();
    var passLength = passWord.length;
    var specialFlag = 0;
    var numberFlag = 0;
    var numberGenerator = 0;
    var total = 0;

    if(/^[a-zA-Z0-9- ]*$/.test(passWord) == false) {

        specialFlag =20;
    }


    if(passWord.match(/[0-9]/)) {

        numberFlag = 25;
    }

    if(passLength>4&&passLength<=6){
        numberGenerator =25;
    }else if(passLength>=7&&passLength<=9){
        numberGenerator =35;
    }else if(passLength>9){
        numberGenerator =55;
    }else if(passLength>0&&passLength<=4){
        numberGenerator =15;
    }else{
        numberGenerator =0;
    }

Hope these set of logic will solve the problem

0

精彩评论

暂无评论...
验证码 换一张
取 消