问题
I am working on an ATG project. My requirement is "the password should not contain the same sequence of characters as in UserName". For eg. If the userName is abcdef@123.com. Then pw should not be def@123.com The pw should not include same SEQUENCE of characters. It can have the characters as in userName. But the ordering/sequence of characters shouldnot be the same.
How can I check this?
Thanks, Treesa
回答1:
You can do the following to check if the password contains any sequence of the username :
public Boolean containsSequences(String uname, String pwd){
Boolean contains=false;
int count=0;
for (String seq: uname.split("/[\@\-\.\_]/g")){ //split the username following this regex.
if(pwd.indexOf(seq)>0){
count++;
}
}
if(count>0){
contains=true;
}
return contains;
}
This method takes two strings(username and pwd) in input, then takes the sub-sequences of the username and test if the pwd contains one of them, if so then return true
menas that the pwd contains a sequence of the username.
Or much better you could do:
public Boolean containsSequences(String uname, String pwd){
Boolean contains=false;
for (String seq: uname.split("/[\@\-\.\_]/g")){
if(pwd.contains(seq)|| pwd.contains(seq.toUpperCase())|| pwd.contains(seq.toLowerCase())){
contains=true;
break;
}
}
return contains;
}
回答2:
use passowrdString.contains(userNameString)
来源:https://stackoverflow.com/questions/28761643/need-to-check-whether-password-contains-same-sequence-of-characters-of-username