本文介绍了验证密码不包含名称中的3个以上连续字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Java中进行密码验证后执行此操作

I need to do this following password validation in Java


  • 长度必须至少为8个字符

  • 必须至少包含1个数字

  • 必须至少包含1个大写字母

  • 必须包含至少1个小写字母

  • 不能包含您的全名或用户名中的3个或更多连续字符(例如,如果您的姓名您无法获得密码 Stiller458

  • Must be at least 8 characters in length
  • Must contain at least 1 number
  • Must contain at least 1 upper case letter
  • Must contain at least 1 lower case letter
  • Cannot contain 3 or more consecutive characters from your full name or your username (e.g. If your name is Will you couldn't have the password Stiller458)

我有前4分,我该怎么做最后一个?

I have the first 4 points, how do I do the last one?

目前我有:

String pattern = "^(?=.*[^a-zA-Z])(?=.*[a-z])(?=.*[A-Z])\\S{8,}$";
boolean passwordValidation = originalPassword.matches(pattern);


推荐答案

对于你的1,2,3,4案例

For your 1,2,3,4 case

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z\d]{8,}$

第5例

public boolean isValid(final String userName,final String password)
{
    for(int i=0;(i+2)<userName.length();i++)
          if(password.indexof(userName.substring(i,i+2))!=-1)
                return false;
    return true;
}

这篇关于验证密码不包含名称中的3个以上连续字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:07