In a controller how can i validate a password so it contains at least 1 letter, 1 number, 1 special character and is at least 8 digits long. The code i am trying to use is as follows:
boolean validatePassword(String password) {
System.out.println("In validate")
def pattern = /^.*(?=.{7,})(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%*&+()]).*$/
def matcher = password =~ pattern
System.out.println("HERERERE")
return matcher.getCount() ? true : false
}
This does not work if says everything is invalid.
I have spring security ui plug in installed. Is there a way I can use its validation features?
I know i can use it to encode the password.
Rather than trying to do everything in one regex I’d split up the tests. Since in Groovy a
Matchercoerces to boolean by callingfind(), the following should work, and makes the intent clearer.