• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regex pattern for validating password

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic