Conditions | 11 |
Paths | 306 |
Total Lines | 37 |
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 |
||
87 | private function cryptApr1Md5($plainpasswd, $salt) { |
||
88 | $len = strlen($plainpasswd); |
||
89 | $text = $plainpasswd.'$apr1$'.$salt; |
||
90 | $bin = pack("H32", md5($plainpasswd.$salt.$plainpasswd)); |
||
91 | for ($i = $len; $i > 0; $i -= 16) { |
||
92 | $text .= substr($bin, 0, min(16, $i)); |
||
93 | } |
||
94 | for ($i = $len; $i > 0; $i >>= 1) { |
||
95 | $text .= ($i & 1) ? chr(0) : $plainpasswd[0]; |
||
96 | } |
||
97 | $bin = pack("H32", md5($text)); |
||
98 | for ($i = 0; $i < 1000; $i++) { |
||
99 | $new = ($i & 1) ? $plainpasswd : $bin; |
||
100 | if ($i % 3) { |
||
101 | $new .= $salt; |
||
102 | } |
||
103 | if ($i % 7) { |
||
104 | $new .= $plainpasswd; |
||
105 | } |
||
106 | $new .= ($i & 1) ? $bin : $plainpasswd; |
||
107 | $bin = pack("H32", md5($new)); |
||
108 | } |
||
109 | $tmp = ''; |
||
110 | for ($i = 0; $i < 5; $i++) { |
||
111 | $k = $i + 6; |
||
112 | $j = $i + 12; |
||
113 | if ($j == 16) { |
||
114 | $j = 5; |
||
115 | } |
||
116 | $tmp = $bin[$i].$bin[$k].$bin[$j].$tmp; |
||
117 | } |
||
118 | $tmp = chr(0).chr(0).$bin[11].$tmp; |
||
119 | $tmp = strtr(strrev(substr(base64_encode($tmp), 2)), |
||
120 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", |
||
121 | "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); |
||
122 | return "$"."apr1"."$".$salt."$".$tmp; |
||
123 | } |
||
124 | } |
||
125 |