dstudio
(Nedim T)
1
Hello everyone,
I’d like to know how password hash is generated?
This is my code:
$email="mail@example.net";
$password="mypassword";
// How to get password_hash variable?
$user = User::find()->where(['email'=>$email, 'password_hash'=>$password_hash])->one();
if(isset($user)){
echo "there is";
} else {
"Sorry!";
}
Thanks.
phtamas
(Phtamas)
2
Fetch User by email and validate password in PHP:
$user = User::find()->where(['email'=>$email])->one();
if(!$user){
// Wrong email
} elseif (!Yii::$app->security->validatePassword($password, $user->password_hash)) {
// Invalid password
} else {
// Ok
}
As far as I understand, the hashing algorithm generates a new random salt string on each call so you cannot simply re-generate the stored value.
dstudio
(Nedim T)
3
Thank you! I’ll try it asap.
EDIT: It works perfectly. Thanks a lot.