我使用的功能是這樣的。
功能check_pass_strength($ PWD) {
if(strlen($pwd) > 20) {
$error .= "Password too long! <br />";
}
if(strlen($pwd) < 8) {
$error .= "Password too short , minimum 8 characters! <br />";
}
if(!preg_match("#[0-9]+#", $pwd)) {
$error .= "Password must include at least one number! <br />";
}
if(!preg_match("#[a-z]+#", $pwd)) {
$error .= "Password must include at least one letter! <br />";
}
if(!preg_match("#[A-Z]+#", $pwd)) {
$error .= "Password must include at least one CAPS! <br />";
}
if(!preg_match("#\W+#", $pwd)) {
$error .= "Password must include at least one symbol! <br />";
}
if($error){
echo "Password validation failure(your choise is weak):<br /> $error";
return 0;
} else {
return 1;
}
} 你可以修改它爲您的需求,瞧!
你需要爲此使用正則表達式嗎?如果你沒有使用正則表達式,它會容易得多(而且更可讀)。 –
至少,您需要定義「特殊字符」。 – delnan
任何特定的編程語言? – aioobe