-1

My problem is to create a policy password that contains:

  • upper case alphabetic characters - done
  • lower case alphabetic characters - done
  • digits - done
  • special charakters - done
  • don't allow alphabetic/digits sequences e.g. qwerty, 12345, qazws, poiuy, 09876, abcde etc. - failure

Can anyone please clarify if this can be done through Regular Expression or is it better to implement through Java library e.g. vtpassword. If possible can anyone please provide me a sample code?

atezor
  • 3
  • 6
  • 2
    "alphabetic/digits sequences" You've got some pretty arbitrary sequences there, as in, there's no pattern other than they are adjacent on certain keyboard layouts. You'd have to enumerate all the illegal sequences and check them all. – Andy Turner Nov 15 '16 at 20:12
  • Is this workplace password validation or school password validation? I can provide some insight on the latter but something of the former should be done through something more rigorous. – Compass Nov 15 '16 at 20:14
  • @AndyTurner Yes, just about sequences in the vicinity of certain keys. – atezor Nov 15 '16 at 20:51
  • Build a dictionary which has the minimum number of unacceptable sequential characters. For example, if there cannot be 3 or more qwerty characters in a row then your dictionary only needs to contain all the possible 3 character qwerty sequences. Then check if any 3 adjacent characters of the password are in the dictionary. Then reverse the password and check again. – Andrew S Nov 15 '16 at 21:45

1 Answers1

0

I solved my problem some time ago and I would like to share my code: The sequence could not contain the first 5 characters of the mechanical password.

public boolean specialChar(String password){

    String sequences = "!@#$%^&*()(*&^%$#@!";
    boolean specbool = false;

    Pattern pp = Pattern.compile("\\p{Punct}{5}+");
    Matcher mm = pp.matcher(password);
    if (mm.find()){
        String q = mm.group();
        specbool = sequences.contains(q);
    }

    return specbool;
}
Tom
  • 16,842
  • 17
  • 45
  • 54
atezor
  • 3
  • 6