How to store passwords in a database table

倾然丶 夕夏残阳落幕 提交于 2019-12-06 11:20:17

I think a common tactic is to make a hash of the password using something like SHA-256 and storing that in the database. Then to log in, you hash whatever the user enters and compare it with what is in the database.

This systems means that your "encryption" is one way. You cannot retrieve the password given the password hash. Note that this has usability consequences. Specifically, you cannot send users their password. You can only reset passwords.

A further improvement would be to salt the password before you hash it. This prevents a class of attacks involving rainbow tables. You should almost certainly do this as well as hashing the password.

As mentioned by other people, it is also important to iterate this several times to prevent brute-force attacks.

Never store the password. Store a hash of the password.

Note that this is not encryption. Hashing and encrypting are related, but they are not the same.

The best thing you can do is use a standard password hashing function such as bcrypt or pbkdf2. Don't reinvent the wheel.

This article has an excellent description of how to store passwords securely.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!