Need to Check whether password contains same sequence of characters of UserName in JAVA/ATG

匆匆过客 提交于 2019-12-11 03:52:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!