Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

密码强度检测js (转自个人百度空间) #19

Open
mishe opened this issue Dec 2, 2015 · 0 comments
Open

密码强度检测js (转自个人百度空间) #19

mishe opened this issue Dec 2, 2015 · 0 comments

Comments

@mishe
Copy link
Owner

mishe commented Dec 2, 2015

function passwordLevel(str,num) {
  var len=str.length,level,num=num||6;

  if(!/\s/g.test(str)){
  level=passwordFormat(str)
  return level==0?0:(len>=num && level>2)?level:(len>num?level:(level>2?--level:1))
  }
  else{
      return 0
  }

}

function passwordFormat(str){
    var i=0,ret = str.match(/^(\d+|[a-z]+)$|^([a-zA-Z0-9]+)$|^([\w~!@#$%^&*_]+)$/);
  if(ret){
    while (ret[++i] === undefined);
    return i;
  }else{
   return 0
  }
}
console.log(passwordLevel(" "));  //0
console.log(passwordLevel(" 13123"));//0
console.log(passwordLevel("123")); //1
console.log(passwordLevel("sss21312"));//2
console.log(passwordLevel("123xx"));//1
console.log(passwordLevel("123xxZ"));//1
console.log(passwordLevel("众收到货"));//0
console.log(passwordLevel("%$#@12"));//3
console.log(passwordLevel("%$#@1"));//2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant