3.134.81.206 |    

Navigation

Google Advertisement



crypt_apr1_md5
  1. // APR1-MD5 encryption method (windows compatible)
  2. // See: http://stackoverflow.com/questions/1038791/how-to-programmaticaly-build-an-apr1-md5-using-php
  3. function crypt_apr1_md5($plainpasswd, $salt = Null) {
  4.  
  5. (string) $tmp = Null;
  6. (string) $translateTo = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  7. if (!strlen($salt)>0) $salt = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 8);
  8. (integer) $len = strlen($plainpasswd);
  9. (string) $text = $plainpasswd.'$apr1$'.$salt;
  10. $bin = pack("H32", md5($plainpasswd.$salt.$plainpasswd));
  11.  
  12. for($i = $len; $i > 0; $i -= 16) { $text .= substr($bin, 0, min(16, $i)); }
  13. for($i = $len; $i > 0; $i >>= 1) { $text .= ($i & 1) ? chr(0) : $plainpasswd{0}; }
  14.  
  15. $bin = pack("H32", md5($text));
  16.  
  17. for($i = 0; $i < 1000; $i++) {
  18. 	$new = ($i & 1) ? $plainpasswd : $bin;
  19. 	if ($i % 3) $new .= $salt;
  20. 	if ($i % 7) $new .= $plainpasswd;
  21. 	$new .= ($i & 1) ? $bin : $plainpasswd;
  22. 	$bin = pack("H32", md5($new));
  23. }
  24. for ($i = 0; $i < 5; $i++) {
  25. 	$k = $i + 6;
  26. 	$j = $i + 12;
  27. 	if ($j == 16) $j = 5;
  28. 	$tmp = $bin[$i].$bin[$k].$bin[$j].$tmp;
  29. }
  30. $tmp = chr(0).chr(0).$bin[11].$tmp;
  31. echo "\$tmp:".$tmp."\n";
  32. echo "strrev(substr(base64_encode())): ".strrev(substr(base64_encode($tmp), 2))."\n";
  33. $tmp = strtr(strrev(substr(base64_encode($tmp), 2)),
  34.     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
  35.     $translateTo);
  36. echo "\$tmp:".$tmp."\n";
  37. return "$"."apr1"."$".$salt."$".$tmp;
  38.  
  39. }
Parsed in 0.011 seconds at 132.77 KB/s

Search
 
Full text search by name and content of a snippet.

User online
There are 1 users online.

Tags Cloud

Latest snippets
str2seconds
(Bash::Function)
is_integer
(Bash::Function)
file_rotate
(Bash::Function)
confirm
(Bash::Function)
is_workingtime
(Bash::Function)
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)