It's usually not recommended to implement your own hashing layer. I'm sure md5 will be fine if you're just doing a really tiny site for learning purposes, but if you're storing important information for a larger site you should use a library, such as PHPass:
Thank you to Jacco for this PHPass code snippet:
require('PasswordHash.php');
$pwdHasher = new PasswordHash(8, FALSE);
// $hash is what you would store in your database
$hash = $pwdHasher->HashPassword( $password );
// $hash would be the $hashed stored in your database for this user
$checked = $pwdHasher->CheckPassword($password, $hash);
if ($checked) {
echo 'password correct';
} else {
echo 'wrong credentials';
}
If you insist on doing it yourself, you should salt the passwords. See http://phpsec.org/articles/2005/password-hashing.html.
define('SALT_LENGTH', 9);
function generateHash($plainText, $salt = null)
{
if ($salt === null)
{
$salt = substr(md5(uniqid(rand(), true)), 0, SALT_LENGTH);
}
else
{
$salt = substr($salt, 0, SALT_LENGTH);
}
return $salt . sha1($salt . $plainText);
}
The reason for the difference between GET and POST is the way the browsers interpret the requests. As mentioned above, web crawlers won't execute POST requests. But imagine that you went to a page on your site http://example.com/deleteuser.php?userid=25
to delete a nasty spammer. Then you close your browser. The next time you come back firefox reopens that page and you've unfortunately deleted the user who just registered!
Another reason for GET vs. POST is the partial prevention against cross-site request forgeries. If you had a page that logged out the user in a GET request, someone could embed an image tag into a comment or forum post like <img src="http://example.com/logout.php" />
and the browser would be forced to execute the logout operation. So any user who viewed that page would be logged out, even if they were an admin.
Edit: As an aside, you should probably use sha-256 or bcrypt instead of md5, which has been cracked (?).