Hi i have a password strength check in PHP. that looks like this:
public static function validPass($candidate) {
$r1 = '/[A-Z]/'; //1 upper
$r2 = '/[a-z]/'; //2 lower
$r3 = '/[!@#$%^&*()\-_=+{}:<.>]/'; //1 special char
$r4 = '/[0-9]/'; //1 number
//no space
if (preg_match('/\s/',$candidate)) {
return false;
}
if (preg_match_all($r1, $candidate, $o) < 1) {
return false;
}
if (preg_match_all($r2, $candidate, $o) < 1) {
return false;
}
if (preg_match_all($r3, $candidate, $o) < 1) {
return false;
}
if (preg_match_all($r4, $candidate, $o) < 1) {
return false;
}
return true;
}
so 1 capital, 1 lower, 1 number, 1 special char and no spaces allowed
now i am using a javascript validator for the frontend and the only custom feature i can add for password is to add a regex so i have to build this into a regex. I tried and I have so far:
^(?=.*[^a-zA-Z])(?=.*[a-z])(?=.*[A-Z])$
but i dont know how to approach this. What is the best way to perform these checks into a regex?