PHP Md5 Hash

Do you want to learn a fast and easy way to encrypt data in PHP? Well, with the MD5 function you have the solution.

This function, as well as other PHP functions for security, allows encrypt text stringsbe it passwords or any other type of data.

Here is the following information about the MD5 PHP method:

  • Function definition.
  • Example of data hashes with the MD5 function.
  • Key information about its use and the web security.


  • How do you encrypt in PHP with MD5?
  • Encrypt passwords with MD5
    • Example of encrypting text with md5
    • PHP Hash Example with MD5
  • Conclusions of encrypting data with MD5 hashes
  • Any input to learn PHP MD5?

How do you encrypt in PHP with MD5?

Encrypt passwords or any data that can be represented as a string in MD5 is easy. For this purpose we will use the PHP MD5 function.

The MD5 function is used as follows:

$cadena_cifrada =  md5 ($cadena);

The returned value or string is the hash represented as a 32-character hexadecimal number.

Encrypt passwords with MD5

It is very likely that you have come this far because you have read about encrypt passwords with MD5. I must tell you that it is possible and that, although it is not safe at all, if you use it for something quick or in an ecosystem where security matters little, it can be useful.

The result (the hash) returned by the function can be easily stored in the database so that at least you have managed to make this information invisible to the naked eye.

Unfortunately, encryption with the MD5 algorithm is easy to decrypt: all you have to do is search on google to realize how simple it is.

Example of encrypting text with md5

Below you can see an example of the result returned by the hash function:

$hash = md5('srcodigofuente');
echo $hash; //devuelve 6dc8261eb47633e127d341dc805a97c1

You have already seen what the result of encrypting with md5 is: a 32-character string in decimal.

Another way to do this same encryption is with the php hash function, which allows you to use the md5 algorithm among others to encrypt.

PHP Hash Example with MD5

Below you can see the equivalent command:

$hash = md5('srcodigofuente');
echo $hash; //devuelve 6dc8261eb47633e127d341dc805a97c1

Conclusions of encrypting data with MD5 hashes

To finish, I would like to review the characteristics or important data when encrypting with hash:

  1. The PHP MD5 function It is used to obtain the encrypted hash of a text string.
  2. The length of the input string has no maximum size. You can use from a 4-letter word to the text of Don Quixote. Another thing will be if the script or apache run out of RAM.
  3. The output string will always be a 32-character string in hexadecimal.
  4. The results of this encryption are insecure and they can be deciphered. For this, the rainbow table.
  5. For more secure PHP encryption you will need to use the “salt” call (which is no longer recommended) or better yet, use the password_hash encryption function or crypt for passwords.

Any input to learn PHP MD5?

Would you like to add something useful to this content? Well, go ahead, it would be great if you shared your experience, possible advice or doubts about this PHP functionality so that others who arrive here after you can also take advantage of them.

Also, if you share this publication on social networks, you will help us to continue creating content that helps thousands of web programmers.

Thank you!

Leave a Reply