Search code examples
javaatgatg-dynamo

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


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 [email protected]. Then pw should not be [email protected] 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


Solution

  • 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;
    }