How to save your password in the correct posture
Summary
In the past few years, many websites have been deprecated, leading to the leakage of plain text passwords of many users. This article does not discuss the pants removal technology, but focuses on how to properly (as secure as possible) Save the user password.
Hash
It should be the consensus that "encrypt plaintext before saving the Database. This process should be irreversible (the original text cannot be obtained through the encrypted string), so the more appropriate name for this "encryption" process is-Hash:
Hash, which is usually translated as "Hash" and is also directly translated as "Hash. The input of any length is converted to a fixed-length output by means of the hash algorithm. The output is the hash value. This type of conversion is a compression ing, that is, the space of hash values is usually much smaller than the input space, and different inputs may be hashed into the same output, therefore, it is impossible to uniquely determine the input value from the hash value. Simply put, a function compresses messages of any length to a fixed-length message digest.
Our common Hash algorithms are MD5 and SHA. In many cases, we use one of them to encrypt user passwords. The above two types of hash algorithms are mainly used to verify the file/digital signature, but are not suitable for protecting the user password. Although it seems to have played a certain security protection effect for us, but in fact the effect is very poor, especially MD5, the collision value can be found in seconds.
Add salt
As we mentioned above, it is not the correct position to directly hash the user's plaintext and save it. After adding salt?
Let's take a look at the problem solved by adding salt: If the passwords of the two users are the same, the hash value is also the same. Attackers can easily crack the original text by using the lookup table method and it is a matter of fact. Because attackers do not know the user's face values and hash algorithms, they are unlikely to crack them.
Adding salt is indeed the correct idea, provided that: