0x00

Hashing Class

Jul 29th, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. <?php
  2.     final class sec
  3.     {
  4.         public function hash($string, $salt1='', $salt2='', $hash='')
  5.         {
  6.             if(empty($salt1))
  7.             {
  8.                 $h = $this->randHash();
  9.                 $s = array(
  10.                         $this->randSalt(),
  11.                         $this->randSalt()
  12.                       );
  13.                 $string = $s[0] . wordwrap($string, strlen($string) / 2, $s[1]) . $s[0];
  14.                 $string = hash($h, $string);
  15.                 return array(
  16.                         'string' => $string,
  17.                         'salt1'  => $s[0],
  18.                         'salt2'  => $s[1],
  19.                         'hash'   => $h
  20.                         );
  21.             }
  22.             else
  23.             {
  24.                 $string = $salt1 . wordwrap($string, strlen($string) / 2, $salt2) . $salt1;
  25.                 return ( string ) hash($hash, $string);
  26.             }
  27.         }
  28.         private function randHash()
  29.         {
  30.             $h = hash_algos();
  31.             return $h[array_rand($h)];
  32.         }
  33.         private function randSalt()
  34.         {
  35.             $l = array_merge(
  36.                         range('a', 'z'),
  37.                         range('A', 'Z'),
  38.                         range(0, 9),
  39.                         array('!', '"', '�', '$', '%', '^', '&', '*', '(', ')', '[', ']', ':', '{', '}', '~', '#', '|', '\', '@', ';', '.', ',', '<', '>', '/', '?', '+', '=', '_', '-')
  40.                     );
  41.             $tmp = NULL;
  42.             for($i = 0; $i <= mt_rand(5, 12); $i++)
  43.             {
  44.                 $tmp .= $l[array_rand($l)];
  45.             }
  46.             return ( string ) $tmp;
  47.         }
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment