我有嘗試檢查密碼的複雜下面的PHP代碼然而,當我運行它,我似乎並沒有得到有效的結果(見下文)PHP密碼複雜性檢查代碼
while (odbc_fetch_row($rs)) {
$r1='/[A-Z]/'; //Uppercase
$r2='/[a-z]/'; //lowercase
$r3='/[[email protected]#$%^&*()-_=+{};:,<.>]/'; // whatever you mean by 'special char'
$r4='/[0-9]/'; //numbers
if (!preg_match_all($r4, odbc_result($rs,"U_password"))) {
echo "Password doesn't contain numbers: " . odbc_result($rs,"U_Mailbox") . "@" . odbc_result($rs,"U_Domain") . " " . odbc_result($rs,"U_password") . "<br>\n";
}
if (!preg_match_all($r2, odbc_result($rs,"U_password"))) {
echo "Password doesn't contain lowercase letters: " . odbc_result($rs,"U_Mailbox") . "@" . odbc_result($rs,"U_Domain") . " " . odbc_result($rs,"U_password") . "<br>\n";
}
if (!preg_match_all($r1, odbc_result($rs,"U_password"))) {
echo "Password doesn't contain uppercase letters: " . odbc_result($rs,"U_Mailbox") . "@" . odbc_result($rs,"U_Domain") . " " . odbc_result($rs,"U_password") . "<br>\n";
}
}
輸出:
密碼不包含小寫字母:[email protected] lowercasepw
密碼不包含足夠的數字:[email protected] 8B_dip + 3
密碼不包含大寫字母:[email protected] Barrywidg @ t1o
(順便說一句,上面的密碼是不真實的。我只是將小寫字母替換爲其他小寫字母,其他大寫字母替換爲大寫字母,其他數字替換爲其他數字。)
所以我很困惑,爲什麼我的代碼不工作。其他人可以幫忙嗎?
感謝 布拉德
謝謝 - 這似乎是它。 – Brad 2010-12-17 23:44:57