Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 0.96 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. class Hash
  4. {
  5.  
  6.     protected static $saltLength = array('minimum' => 9, 'maximum' => 21);
  7.  
  8.     public static function generateSalt()
  9.     {
  10.         $salt   = '';
  11.         $length = mt_rand( self::$saltLength['minimum'], self::$saltLength['maximum'] );
  12.  
  13.         // Rellena el salt con caracteres aleatorios
  14.         for( $i = 0; $i < $length; $i++ )
  15.         {
  16.             $salt .= chr( mt_rand(33, 126) );
  17.         }
  18.  
  19.         return $salt;
  20.     }
  21.  
  22.     public static function makeUniqueID( $data )
  23.     {
  24.         $rand = mt_rand(0, 10);
  25.         $id   = '';
  26.  
  27.         if($rand > 5)
  28.         {
  29.             $id  = time();
  30.             $id .= $data;
  31.         }
  32.         else
  33.         {
  34.             $id  = $data;
  35.             $id .= time();
  36.         }
  37.  
  38.         $id .= uniqid();
  39.  
  40.         return sha1($id);
  41.     }
  42.  
  43.     public static function encript( $data, $key, $salt = null )
  44.     {
  45.         return hash_hmac('sha512', $salt . $data, $key);
  46.     }
  47.  
  48. }
  49. ?>