| Conditions | 14 |
| Paths | 1224 |
| Total Lines | 95 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 7 | function md5crypt($pw, $salt = "", $magic = "") |
||
| 8 | { |
||
| 9 | $MAGIC = "$1$"; |
||
| 10 | |||
| 11 | if ($magic == "") |
||
| 12 | { |
||
| 13 | $magic = $MAGIC; |
||
| 14 | } |
||
| 15 | |||
| 16 | if ($salt == "") |
||
| 17 | { |
||
| 18 | $salt = create_salt(); |
||
| 19 | } |
||
| 20 | |||
| 21 | $slist = explode("$", $salt); |
||
| 22 | if (isset($slist[0]) && $slist[0] == "1") |
||
| 23 | { |
||
| 24 | $salt = $slist[1]; |
||
| 25 | } |
||
| 26 | |||
| 27 | $salt = substr($salt, 0, 8); |
||
| 28 | $ctx = $pw.$magic.$salt; |
||
| 29 | $final = hex2bin(md5($pw.$salt.$pw)); |
||
| 30 | |||
| 31 | for ($i = strlen($pw); $i > 0; $i -= 16) |
||
| 32 | { |
||
| 33 | if ($i > 16) |
||
| 34 | { |
||
| 35 | $ctx .= substr($final,0,16); |
||
| 36 | } |
||
| 37 | else |
||
| 38 | { |
||
| 39 | $ctx .= substr($final,0,$i); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | $i = strlen($pw); |
||
| 44 | |||
| 45 | while ($i > 0) |
||
| 46 | { |
||
| 47 | if ($i & 1) |
||
| 48 | { |
||
| 49 | $ctx .= chr(0); |
||
| 50 | } |
||
| 51 | else |
||
| 52 | { |
||
| 53 | $ctx .= $pw[0]; |
||
| 54 | } |
||
| 55 | |||
| 56 | $i = $i >> 1; |
||
| 57 | } |
||
| 58 | |||
| 59 | $final = hex2bin(md5($ctx)); |
||
| 60 | |||
| 61 | for ($i=0; $i<1000; $i++) |
||
| 62 | { |
||
| 63 | $ctx1 = ""; |
||
| 64 | if ($i & 1) |
||
| 65 | { |
||
| 66 | $ctx1 .= $pw; |
||
| 67 | } |
||
| 68 | else |
||
| 69 | { |
||
| 70 | $ctx1 .= substr($final,0,16); |
||
| 71 | } |
||
| 72 | if ($i % 3) |
||
| 73 | { |
||
| 74 | $ctx1 .= $salt; |
||
| 75 | } |
||
| 76 | if ($i % 7) |
||
| 77 | { |
||
| 78 | $ctx1 .= $pw; |
||
| 79 | } |
||
| 80 | if ($i & 1) |
||
| 81 | { |
||
| 82 | $ctx1 .= substr($final, 0, 16); |
||
| 83 | } |
||
| 84 | else |
||
| 85 | { |
||
| 86 | $ctx1 .= $pw; |
||
| 87 | } |
||
| 88 | |||
| 89 | $final = hex2bin(md5($ctx1)); |
||
| 90 | } |
||
| 91 | |||
| 92 | $passwd = ""; |
||
| 93 | $passwd .= to64(((ord($final[0]) << 16) | (ord($final[6]) << 8) | (ord($final[12]))), 4); |
||
| 94 | $passwd .= to64(((ord($final[1]) << 16) | (ord($final[7]) << 8) | (ord($final[13]))), 4); |
||
| 95 | $passwd .= to64(((ord($final[2]) << 16) | (ord($final[8]) << 8) | (ord($final[14]))), 4); |
||
| 96 | $passwd .= to64(((ord($final[3]) << 16) | (ord($final[9]) << 8) | (ord($final[15]))), 4); |
||
| 97 | $passwd .= to64(((ord($final[4]) << 16) | (ord($final[10]) << 8) | (ord($final[5]))), 4); |
||
| 98 | $passwd .= to64(ord($final[11]), 2); |
||
| 99 | |||
| 100 | return $magic.$salt.'$'.$passwd; |
||
| 101 | } |
||
| 102 | |||
| 139 | } |