How to add salt?
In order to enhance the safety of MD5, in addition to the new algorithm to add a part of the value of salt, salt value is a randomly generated set of strings, can include random uppercase and lowercase letters, numbers, characters, the number of digits can be based on requirements and different, the use of various salt values produced by the final ciphertext is not the same:
1). First we get the hash value of the plaintext
2). To obtain MD5 plaintext hash value for calculation
3). Randomly generate salt value and insert
4). MD5 Insert add salt to be worth to hash
5). Get the final cipher
Look at a simple add-salt function:
/**
* MD5 add salt function
* by http://www.phpddt.com
/function Do_hash ($PSW) {
$salt = ' FDSAFAGFDGV43532JU76JM '; Define a salt value, preferably long enough, or random
return MD5 ($PSW. $salt);//Returns the hash after salt
Attention:
If you are randomly generated salt, you have to put into the database, do not use time()
the time to poke anything, so that others can not enumerate it, if you are too troublesome, you can configure a complex salt value, as above, the two methods have advantages.
Another complex Point Encryption method:
function Passcrypt ($ManagerPassword)
{
$ManagerPassword =md5 ($ManagerPassword);
$Salt =substr ($ManagerPassword, -1,3);
$ManagerPassword =crypt ($ManagerPassword, $Salt);
return $ManagerPassword;
}
So first encrypt the password with MD5, then intercept the result of a paragraph, and then use crypt encryption, because these two cryptographic functions are one-way, so no one can crack it, and after the encryption of the final password is 13, no matter who got hands do not know how to crack, In the case of password authentication, you only need to encrypt the original password with the encryption function and then the encryption of a series to match on the line.
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.