Password Decryption in Yii2
Yii2 have inbuilt functions for encrypt/decrypt data using secret key. Yii2 getSecurity() method return the pseudo random data which is useful for encrypt/decrypt your hash data. The given example describe the validate password and set password methods:
public $key = 'SECRET KEY';
public function setPassword($pwd)
{
$this->password_hash = Yii::$app->getSecurity()->encryptByPassword($pwd, $this->key);
}
public function validatePassword($pwd)
{
$decryptPassword = Yii::$app->getSecurity()->decryptByPassword($this->password_hash, $this->key);
return $decryptPassword === $pwd;
}
No comments:
Post a Comment