Example #1
0
 /**
  * Hashes an object using salt provided
  *
  * @param   string  $object hash an object
  * @param   string  $salt   Salt to be used with object
  * @param   integer $rounds The number of rounds to hash it by
  * @param   string  $algo   Algorythm to use when hashing
  * @return  StdClass
  */
 public static function hash($object, $salt = null, $rounds = 0, $algo = null)
 {
     $ret = new self();
     $ret->setSalt($salt)->setRounds($rounds);
     // First mix password and salt
     $data = serialize($object) . $salt;
     if (!is_null($algo)) {
         $ret->setAlgo($algo);
     }
     for ($i = 0; $i <= $ret->getRounds(); $i++) {
         $data = hash($ret->getAlgo(), $data);
     }
     $ret->setHash($data);
     return $ret;
 }