如此 < a href=" https://webapps.stackschange.com/ questions/26301/facebook-acceptions-more-than-one-password" 所述,Facebook接受我们密码的截然相反的变换。 例如:
1.- paSSw5ORD (Original password)
2.- PAssW5ord (Case altered to exact opposite, Capital->Small and vice-versa.)
3.- PaSSw5ORD (Only first letter s case altered)
How to get the second variation, provided the first one is the original one, entered by user (or to get first one when user enters second version)? Here is my take on this.
<?php
$pass = "paSSw5ORD"; //Example password
$pass_len = strlen($pass); //Find the length of string
for($i=0;$i<$pass_len;$i++){
if(!(is_numeric($pass[$i]))){ //If Not Number
if($pass[$i]===(strtoupper($pass[$i]))){ //If Uppercase
$pass2 .= strtolower($pass[$i]); //Make Lowercase & Append
} else{ // If Lowercase
$pass2 .= strtoupper($pass[$i]); //Make Uppercase & Append
}
} else{ //If Number
$pass2 .= $pass[$i]; //Simply Append
}
}
//Test both
echo $pass."
";
echo $pass2;
?>
但如何用特殊字符处理密码(在标准的英语键盘上尽可能使用?)
!@#$%^&*()_+|?><":}{~[]; ,./ (Space also)
这对以上所有特殊字符都行不通。
if(preg_match( /^[a-zA-Z]+$/ , "passWORD")){
//Special Character encountered. Just append it and
//move to next cycle of loop, similar to when we
//encountered a number in above code.
}
我不是RegEx的专家,所以如何修改上述RegEx以确保它处理上述所有特殊人物?