java 密码是字母和数字的组合_java密码规则,必须同时包含字母和数字并且不能连续4位以上...

/**

* 密码是否是正序或反序连续4位及以上

* @param pwd

* @return true为正确,false为错误。

*/

public static boolean isPasswordContinuous(String pwd) {

int count = 0;//正序次数

int reverseCount = 0;//反序次数

String[] strArr = pwd.split("");

for(int i = 1 ; i < strArr.length-1 ; i ++) {//从1开始是因为划分数组时,第一个为空

if(isPositiveContinuous(strArr[i],strArr[i+1])) {

count ++;

}

else {

count = 0;

}

if(isReverseContinuous(strArr[i],strArr[i+1])) {

reverseCount ++;

}

else {

reverseCount = 0;

}

if(count > 2 || reverseCount > 2) break;

}

if(count > 2 || reverseCount > 2) return false;

return true;

}

/**

* 是否是正序连续

* @param str1

* @param str2

* @return

*/

public static boolean isPositiveContinuous(String str1 , String str2) {

if(str2.hashCode() - str1.hashCode() == 1) return true;

return false;

}

/**

* 是否是反序连续

* @param str1

* @param str2

* @return

*/

public static boolean isReverseContinuous(String str1 , String str2) {

if(str2.hashCode() - str1.hashCode() == -1) return true;

return false;

}

/**

* - 字母区分大小写,可输入符号

- 密码必须同时包含字母和数字

- 密码长度8-20位

- 密码中不能存在连续4个及以上的数字或字母(如:1234、7654、abcd、defgh等)

- 密码中不能包含个人手机号后4位

@author Miaozz.

@param phone 手机号码

* @param password 密码

* @return true为正确,false为错误

*/

public static boolean isPasswordAvailable(String phone,String password) {

String last4No = phone.substring(phone.length()-4);

String str = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$";//必须同时包含字母数字并且是8-20位

if(!password.contains(last4No) && password.matches(str)) {

return isPasswordContinuous(password);

}

return false;

}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值