Hash... What is it?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Hash... What is it?

Post by Jim »

This is a dumb question, but I've been searching through the PHP.net documentation for a defintion of Hash.

They say Hash frequently in their docs, but I never understand what it means. It seems to be commonly associated with Arrays.

What does it mean? Thanks!
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Hashes...

Post by gotDNS »

hashing is an encryption process, basically. In PHP, a common hash is the hash function: md5()

md5 converts a user input value to a 32 character long string. Evertime you hash it you will get the same thing. So say you have them put a password in an imputbox with the name of $pw. Wehn you submit the script you hash it first before you add it to the database...md5($pw)

So now you have a hashed password in the database. Then for the username they insert, when they log in, you make sure that the hash of the password matches the 32 character long string in the database. Remember, it hashes to the same thing every time. Now don't take it the wrong way, the hash cannot be undone.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

its essentially another choice for doing checksums (md5 that is). there's CRC of varing bits and a few others. using md5 just happens to give a more secure checksum of the string.
Skorpion
Forum Newbie
Posts: 4
Joined: Sat May 11, 2002 7:50 am

Post by Skorpion »

If "hash" is a term used in connection with arrays, would that not be referring to perl slang for the ever-so-useful associative arrays?

Not that I'm denying the md5 use of "hash".
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Yes, hash in this sense is not being used as method of encryption.

Hash is refering to what we commonly in PHP call an associative array.

Example of an Associative Array:

Code: Select all

$person = array ( 'fname' => 'Jason', 'lname' => 'Lotito', 'age' => 22 );
You can reference each element of the array like so:

Code: Select all

echo $personї'fname']; // prints Jason
echo $personї'lname']; // prints Lotito
echo $personї'age']; // prints 22
Or you can loop through this associative array (or hash) like so:

Code: Select all

foreach ( $person as $key => $description )
{
        echo "$key == $person<br>";
}
/* prints
fname == Jason
lname == Lotito
age == 22
*/
The term hash comes from Perl, where associative arrays are called a hash.
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

echo "$key == $description<br>";
:wink:
Post Reply