• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regex in Java to validate Password that matches Active Directory Default Password  RSS feed

 
Mckenzie John
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i have a regex to validate a username with the following requirements -

1) Can start with lowerCase or Uppercase A-Z
2) Can include_ or . or - anywhere in the string but not at the first character
3) Can Include special characters - @ & anywhere in the string but not at the first character
4) Should be of minimum 3 characters in length
5) Should not include special characters - !#$%^*()/*-+/\

I had come up with a Regex :
String user = "[a-zA-Z0-9\\._\\-](?!#$%^*()/*-+/\]) {3,}"; \\ Not sure how to exlcude / and \ here

Can some one help me in this and also help me understand the right expression.

I also have another requirement where i need to meet default AD password Policy. in net i came across the following patter:

(?=^.{8,255}$)((?=.*[A-Z])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*

Can some one help me make sense of this?

Thanks in Advance !!!
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your specification looks to be incomplete and ambiguous -

a) - In (1) should that not be "Can Must start with lowerCase or Uppercase A-Z" ?
b) - (2), (3) and (5) all seem to be just to define the set of exclusions so why are they separated into 3 groups ?
c) - What about the other 'special characters' such as non English letters?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest not making a single regex that does the whole thing. Have several, each doing one part, for the following reasons:

1) it's easier. Writing a regex that tests each part is almost trivial.
2) It is more understandable. The regex you wrote breaks my brain - and isn't even complete from what you posted. but I (and almost everyone else) can easily understand "^[A-Za-Z].*" and the other ones required.
3) someday your specs will change, and your overly complicated regex will be broken. If you have the requirements in individual regexes (and by implication, separate methods), you can easily zero in on what needs to be changed, removed, or added.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!