How to add salt random salt value to MD5-related tips

Source: Internet
Author: User
Tags crypt hash md5

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.