PHP: What is Hash? | Hashing a String | Generate Hash of Strings

by Yang Yang on April 22, 2009

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.

Subscribe to Kavoir: blog feed

You should also read:

Comments on this entry are closed.

Previous post:

Next post: