// a valid password should contains:
// at least 1 upper case letter, 1 lower case letter, 1 number, 1 special character,
// and 8 characters in length
function valid_pass($candidate) {
$r1='/[A-Z]/'; //uppercase
$r2='/[a-z]/'; //lowercase
$r3='/[0-9]/'; //numbers
$r4='/[~!@#$%^&*()\-_=+{};:?]/'; // special char
if(preg_match_all($r1,$candidate, $o)<1) {
echo "密码必须包含至少一个大写字母,请返回修改!
";
return FALSE;
}
if(preg_match_all($r2,$candidate, $o)<1) {
echo "密码必须包含至少一个小写字母,请返回修改!
";
return FALSE;
}
if(preg_match_all($r3,$candidate, $o)<1) {
echo "密码必须包含至少一个数字,请返回修改!
";
return FALSE;
}
if(preg_match_all($r4,$candidate, $o)<1) {
echo "密码必须包含至少一个特殊符号:[~!@#$%^&*()\-_=+{};:?],请返回修改!
";
return FALSE;
}
if(strlen($candidate)<8) {
echo "密码必须包含至少含有8个字符,请返回修改!
";
return FALSE;
}
return TRUE;
}