I need to do this following password validation in Java
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)
I have the first 4 points, how do I do the last one?
Currently I have:
String pattern = "^(?=.*[^a-zA-Z])(?=.*[a-z])(?=.*[A-Z])\\S{8,}$";
boolean passwordValidation = originalPassword.matches(pattern);
解决方案
For your 1,2,3,4 case
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z\d]{8,}$
For your 5th case
public boolean isValid(final String userName,final String password)
{
for(int i=0;(i+2)
if(password.indexof(userName.substring(i,i+2))!=-1)
return false;
return true;
}