如
Meta Question所述,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)
如何获得第二个变体,前提是第一个变体是原始变体,由用户输入(或者在用户输入第二个版本时获得第一个变体)?
这是我对此的看法.
<?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."\r\n"; 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以确保它处理所有上述特殊字符?
这是一个切换字符串中字符大小写的函数.
原文链接:https://www.f2er.com/php/132034.html<?PHP $string = "Hello"; // the string which need to be toggled case $string_length = strlen($string); // calculate the string length for($i=0;$i<$string_length;$i++){ // iterate to find ascii for each character $current_ascii = ord($string{$i}); // convert to ascii code if($current_ascii>64 && $current_ascii<91){ // check for upper case character $toggled_string .= chr($current_ascii+32); // replace with lower case character }elseif($current_ascii>96 && $current_ascii<123){ // check for lower case character $toggled_string .= chr($current_ascii-32); // replace with upper case character }else{ $toggled_string .= $string{$i}; // concatenate the non alphabetic string. } } echo "The toggled case letter for $string is <hr />".$toggled_string; // output will be hELLO ?>
希望对你有帮助
在这个link中给出了相同的例子.