Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Phpass extends CApplicationComponent
- {
- // Path to the phpass library
- public $libPath = 'application.vendors.phpass.PasswordHash';
- // Do we require the hashes to be portable to older systems? This is less secure. (This requires PHP 5.3 or Suhosion.)
- public $hashPortable = false;
- // Base-2 logarithm of the iteration count used for password stretching
- public $hashCostLog2 = 10;
- public function init()
- {
- $lib = Yii::getPathOfAlias($this->libPath) . '.php';
- if (!file_exists($lib)) {
- Yii::log("phpass lib not found ($lib)!", CLogger::LEVEL_WARNING, 'Phpass');
- throw new CHttpException(500, "phpass lib not found ($lib)!");
- }
- Yii::import($this->libPath, true);
- return parent::init();
- }
- // Reset PasswordHash to generate a new random state
- private function _getHasher()
- {
- return new PasswordHash($this->hashCostLog2, $this->hashPortable);
- }
- public function getHash($password)
- {
- $hash = $this->_getHasher()->HashPassword($password);
- if (strlen($hash) < 20)
- throw new CHttpException(500, 'Problem hashing password, please contact support.');
- return $hash;
- }
- public function compare($password, $hash)
- {
- return $this->_getHasher()->CheckPassword($password, $hash);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement