How to decrypt md5 password in PHP?

In this article, we will discuss how to decrypt the md5 password in PHP. Before that, let us see how to encrypt the password by md5 hashing.

How to encrypt the password in PHP?

In PHP, the method like- md5() is used to encrypt a password.

Syntax:-




md5(string,raw);

Example:-

<?php

//String to be hashed
$data = "Hello Codespeedy";

//hashed data
echo md5($data);
?>

Output:-

ea12b5f69c8ef8d3a89e0437fe6fca88

Let us discuss another double md5 hashing technique to encrypt username as well as the password using a key.

<?php
//User Credentials
$user_id = "Codespeedy";
$password = "User123";

//catalyst to the encryption
$key = "qwertyuiop"; 
$encrypt_password = md5(md5($user_id . $password) . $key);

//display encrypted password
echo $encrypt_password;
?>

Output:-

The output of our code will be looks like you can see below:

6193eccf4cd9fba9894f093ca103c3f7

How to decrypt the password in PHP?

Actually, there are no such methods to decrypt an md5 password. But we can only achieve it by comparing it with the encrypted data. Here we are just going to compare our string with the decrypted value.

Example:-

<?php
//data input by the user
$data = "Hello Codespeedy";

//Checcking with our hashed data
if (md5($data) == "ea12b5f69c8ef8d3a89e0437fe6fca88")
  {
  echo "<br>Hello Codespeedy";
  exit;
  }
?>

Output:-

Hello Codespeedy

Let us decrypt the double md5 encrypted data using the same comparing technique,

<?php
//User Credentials to be checked
$user_id = "Codespeedy";
$password = "User123";

//Key to decrypt
$key = "qwertyuiop"; 

//Comparing with our hashed data
if(md5(md5($user_id . $password) . $key)=='6193eccf4cd9fba9894f093ca103c3f7')
  echo "<br>Username:".$user_id."<br>Password:".$password;
?>

Output:-

Username:Codespeedy
Password:User123

This is how we can decrypt an md5 password in PHP. As you can see, this is actually not decrypting. Here we have just compared our string with the encrypted value and check if the encrypted value of our string is same as the md5 string or not.

If you have any doubt on this article, Put a comment below,

See also,


Leave a Reply

Your email address will not be published. Required fields are marked *