Page 1 of 1
Hash... What is it?
Posted: Fri May 10, 2002 3:15 pm
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!
Hashes...
Posted: Fri May 10, 2002 3:33 pm
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.
Posted: Fri May 10, 2002 8:58 pm
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.
Posted: Sat May 11, 2002 7:50 am
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".
Posted: Sat May 11, 2002 9:28 am
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.
Posted: Sat May 11, 2002 10:26 am
by dusty
echo "$key ==
$description<br>";
