comparing salt and hashed passwords during login doesn't seem work right

可紊 提交于 2019-12-04 20:55:51

Right now you are generating a different salt upon registration and login. You need to use the same salt for hashing or you will get different hashes. That is to say you need store the salt into the database along with the password and reuse it to hash when the user tries to login later.

Steps:

  1. User registers and provides a plain text password
  2. You generate a new random salt and use it to hash the plain text
  3. You store the salt and the hash into the database
  4. Later the user tries to login by providing a new plain text password. You fetch the hash and the salt from database
  5. You use the salt to hash the plain text
  6. Compare the two hashes
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!