/** * Class constructor * * @param string $salt */ public function __construct($salt = null) { if ($salt === null) { $salt = Steelcode_String_Helper::randomString(32); } if (32 === Steelcode_String_Helper::safeLength($salt)) { $this->_salt = $salt; } else { throw new Steelcode_Crypto_Exception('Salt should be exactly 32 characters long'); } }
/** * Hash a given password using BlowFish algorithm * * @param string $password * @return string */ public function hash($password) { if ($this->_salt === null) { $randomString = Steelcode_String_Helper::randomString(10); $randomSalt = substr(sha1($randomString), 0, 22); } else { $randomSalt = $this->_salt; } $this->_salt = null; $hashCount = $this->_loopCount; $hashPassword = "******"; while ($hashCount >= 0) { $hashPassword = sha1(sprintf("%s%s%d", $hashPassword, $randomSalt, $hashCount)); $hashCount--; } $hashPassword = crypt($hashPassword, '$2y$12$' . $randomSalt . '$'); echo $randomString . "<br>"; $hashLength = strlen($hashPassword); exit(sprintf("%s%s", $randomSalt, substr($hashPassword, 29, $hashLength))); }