I am building a super simple function to ensure a password contains specific characters. Namely, the password should have the following:
#|
MatchString
lowercaseMatch := regexp.MustCompile(`[a-z]`).MatchString
uppercaseMatch := regexp.MustCompile(`[A-Z]`).MatchString
digitMatch := regexp.MustCompile(`\d`).MatchString
specialMatch := regexp.MustCompile(`\W`).MatchString
badCharsMatch := regexp.MustCompile(`[\s#|]`).MatchString
if (lowercaseMatch(pwd)
&& uppercaseMatch(pwd)
&& digitMatch(pwd)
&& specialMatch(pwd)
&& !badCharsMatch(pwd)) {
/* password OK */
} else {
/* password BAD */
}
While this makes things pretty readable, I would prefer a more concise regex, but I don't know how to get regex to search for a single character of each of the above categories (regardless of position). Can someone point me in the right direction of how to achieve this? Additionally, if there is a better way to do this than regex, I am all ears.
Thanks!