Using hashing to safely store user passwords

邮差的信 提交于 2019-12-05 12:36:00

you need to hash the user input password and compare hashes.

Before comparing the posted password by the user with the one in the database, encrypt the posted password the same way as the stored password.

All you need to do is encrypt the password you type in and compare the two; the hash in the database and the one you just encrypted. If they match then the password entered is the right one. I am assuming you are using an algorithm like SHA1.

Licky Lindsay

As already answered, you need to hash the password every time they re-enter it and compare the hash to what is in your database.

You ALSO should look into using salt in your hashing algorithm. There is a good deal of discussion in this question:

Secure hash and salt for PHP passwords

You dont need to decrypt it. You cannot convert back a hash to a plain text, its a one way function. So, basically you hash the input password and compare the two hash:

E.g (pseudo code):-

if hash(password entered by user) == password stored in databse Then
    //logged in successfully
else
    //login failed
end if

I highly recommend using md5() http://php.net/manual/en/function.md5.php.

When the user signs up, you store:

$password = md5($_POST['password']);

And when the user logs in you check:

if($_POST['password_entered'] == $passwordFromDB) :
    // Log user in
else :
    // Show error to user
endif;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!