rpicms

A CMS for the Raspberry Pi
git clone git://archive.git.mtrnord.blog/RpicmsTeam/rpicms.git
Log | Files | Refs | README | LICENSE

PassHash.class.php (751B)


      1 <?php
      2  
      3 class PassHash {
      4  
      5     // blowfish
      6     private static $algo = '$2a';
      7     // cost parameter
      8     private static $cost = '$10';
      9  
     10     // mainly for internal use
     11     public static function unique_salt() {
     12         return substr(sha1(mt_rand()), 0, 22);
     13     }
     14  
     15     // this will be used to generate a hash
     16     public static function hash($password) {
     17  
     18         return crypt($password, self::$algo .
     19                 self::$cost .
     20                 '$' . self::unique_salt());
     21     }
     22  
     23     // this will be used to compare a password against a hash
     24     public static function check_password($hash, $password) {
     25         $full_salt = substr($hash, 0, 29);
     26         $new_hash = crypt($password, $full_salt);
     27         return ($hash == $new_hash);
     28     }
     29  
     30 }
     31  
     32 ?>