| Hash Generator | Usage Guidance |
The syntax for the MD5 function is very simple.
<?php md5("string or variable"); ?>
MD5 Is a method of "one-way-encryption". This means that it does not have a decrypt function. At first glance this may seem pointless as there is no way to restore the original information. This is not the case however.
Let's imagine that we have used our hash generator to generate a secret password. If we wanted our password to be qwerty then we would put that into the box and click get hash. This gives us a 32 character code that is unique. The hash for qwerty (MD5 is case sensitive - QWERTY gives a different value than Qwerty or qwerty) is
Now, as we mentioned above, MD5 has no decrypt function. This means that the string above can never be returned to qwerty without brute force attack. This means that our secret password (qwerty) can not be read by humans. Even if your database was compromised your users passwords would be kept safe.
But now I am sure you are wondering, if there is no decrypt function what use is this? The trick with One Way Encryption is to think of comparing a MD5 sum from a form to one you have on file already. The best way to show this is with an example:
<?php
$entered_pass = $GET[ "password"];
$hash = md5($entered_pass);
if($hash == "d8578edf8458ce06fbc5bb76a58c5ca4")
{
//Some Private Stuff
} ?>
The above code assumes would be the processor for a Web Form with a single input (password). The PHP code gets the value of password (probably sent by the POST method) then assigns it the shorter variable name of $entered_pass. The next step is to generate the MD5 hash for $entered_pass. Then the script compares the MD5 hash of the given password to the one that we had safely on file. If they are the same then the password must have been correct and the secret code can be executed. Of course in a practical environment the correct hash would probably be in a database full of usernames and passwords but the theory holds true.