D
D
Daniil Sidorov2018-03-28 18:38:25
Yii
Daniil Sidorov, 2018-03-28 18:38:25

Why is the password hash method not working in yii2?

Hello, I am making a User model. Wrote a method:

public function setPassword($password)
    {
        $this->password = Yii::$app->security->generatePasswordHash($password);
    }

But for some reason it is underlined by phpstorm.
c06fcdbd90033d895f3156ac3446e786.png
What could be wrong? thank.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-03-28
@DaniLaFokc

1. The fact that it is underlined by phpStorm does not mean that it is a mistake.
2. Add a backslash before Yii or add it to use. Yii came out of nowhere for you.

D
Denis, 2018-03-28
@sidni

With incorrect input values, this method (generatePasswordHash) can return an exception, which for good (as Phpstorm says) you need to put a try catch block, or you have a function description at the top and you need to indicate there that your method (setPassword) can return an exception

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question