This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Groovy and the fly likes Regex pattern for validating password Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Regex pattern for validating password" Watch "Regex pattern for validating password" New topic
Author

Regex pattern for validating password

Dinh Hong Chau
Greenhorn

Joined: Jan 16, 2011
Posts: 1
Hi,
I am working with a small issue, but I don't know how to solve it clearly. I have to validate a generated password, with some constraints:
- password length: [8, 24]
- password contains
+ at least 1 lower case character
+ at least 1 upper case character
+ at least 1 digit
+ at least 1 special character (printable based on ASCII code)
I've used Regex pattern, but it didn't work correctly with both cases: valid and invalid.

The first RegEx pattern: def pattern = /(=?.{8,24})((:?[a-z]+)(:?[0-9]+)(:?[A-Z]+)(:?\W+))/ can check all invalid passwords but not for the valid one.
The second RegEx pattern: def pattern = /(=?.{8,24})((:?[a-z]*)(:?[0-9]*)(:?[A-Z]*)(:?\W*))/ can check all valid passwords but not for the invalid one.
I am new to Groovy, so I don't know how to create the correct RegEx pattern to solve this.
Could you please help me?
Thank you very much.
Oscar Hansen
Greenhorn

Joined: Jul 09, 2008
Posts: 10
Have you tried using custom validators for a password field? I was running into a similar issue once and using custom validators did resolve my issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex pattern for validating password
 
Similar Threads
Help with Password Checker
Re: password policy
A regex problem
Regular expressions to handle sequence of special characters
Regular expression