Commit 56622469 by zhangchen

Merge branch 'f-6.7.0' of 192.168.10.6:caosy/fun-common into f-6.7.0

parents 31944e81 4cc69d03
package com.ctrip.fun.common.core.util;
public class CheckPassword {
/**
* 密码强度
*
* @return Z = 字母 S = 数字 T = 特殊字符
*/
/* 一、假定密码字符数范围6-16,除英文数字和字母外的字符都视为特殊字符:
弱:^[0-9A-Za-z]{6,16}$
中:^(?=.{6,16})[0-9A-Za-z]*[^0-9A-Za-z][0-9A-Za-z]*$
强:^(?=.{6,16})([0-9A-Za-z]*[^0-9A-Za-z][0-9A-Za-z]*){2,}$
二、假定密码字符数范围6-16,密码字符允许范围为ASCII码表字符:
弱:^[0-9A-Za-z]{6,16}$
中:^(?=.{6,16})[0-9A-Za-z]*[\x00-\x2f\x3A-\x40\x5B-\xFF][0-9A-Za-z]*$
强:^(?=.{6,16})([0-9A-Za-z]*[\x00-\x2F\x3A-\x40\x5B-\xFF][0-9A-Za-z]*){2,}$*/
public static int checkPassword(String passwordStr) {
if(passwordStr.length()<6){
return -1;
}
String regexZ = "\\d*";
String regexS = "[a-zA-Z]+";
String regexT = "\\W+$";
String regexZT = "\\D*";
String regexST = "[\\d\\W]*";
String regexZS = "\\w*";
String regexZST = "[\\w\\W]*";
if (passwordStr.matches(regexZ)) {
return 1;
}
if (passwordStr.matches(regexS)) {
return 1;
}
if (passwordStr.matches(regexT)) {
return 1;
}
if (passwordStr.matches(regexZT)) {
return 2;
}
if (passwordStr.matches(regexST)) {
return 2;
}
if (passwordStr.matches(regexZS)) {
return 2;
}
if (passwordStr.matches(regexZST)) {
return 3;
}
return 1;
}
public static void main(String args[]){
String pswd = "Huan3";
Integer strength = CheckPassword.checkPassword(pswd);
System.out.println("密码强度: "+strength);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment