1

I am trying to encrypt a password using the PHP crypt function. In yii, it's recommended to use CPasswordHelper. When I call CPasswordHelper::hashPassword($password), it says Class 'common\models\CPasswordHelper' not found.

Please help?

DSEJ
  • 131
  • 4

1 Answers1

4

To generate hashed password in Yii 2 use security component.

You can generate password hash with:

$hash = \Yii::$app->getSecurity()->generatePasswordHash($rawUserPassword);

To validate this password later on you can check:

if (\Yii::$app->getSecurity()->validatePassword($rawUserPassword, $hash) {}

Read more about this in the Guide.

Bizley
  • 17,392
  • 5
  • 49
  • 59