A hash or digest can be thought of as the digital fingerprint of a piece of data. Hash is usually generated from any string of text in a fixed length by a one-way mathematical process. It is next to impossible to re-engineer the original text or data from the hash alone. Also, it is vast impossible that any different text strings share an identical hash.
Thus, a hash of a string is usually used to encrypt clear text yet to maintain the possibility to compare encrypted texts for identicalness or check if the original text has been modified in any way.
To hash a string or get the hash of a string in PHP, use sha1() instead of md5() which is inferior than sha1() with regards to security.
$hash = sha1('The deal is $120,000 in total.');
And $hash contains the sha1 hash of the string in the argument. Here’s a better read on how to hash your passwords.
You should also read:
- The Secure Way to Store Passwords with PHP
- How to create / generate .htpasswd password with PHP dynamically?
- One Simple Way to Encrypt, Obfuscate, Hide or Protect Your PHP Code
- Just Hashing is Far from Enough for Storing Passwords – How to Position against Dictionary and Rainbow Table Attacks
- PHP: Check if A String Contain Only Uppercase / Capital Letters