i need help understanding password security. concept of salts, nonce etc.
i read http://stackoverflow.com/questions/401656/secure-hash-and-salt-for-php-passwords but its quite advanced for me. i don't really understand what problems salts etc solve, and how it is implemented, maybe from the basics
// basics i learnt from school, using md5 for user input
SELECT UserID, Username FROM Users
WHERE Username = "user1"
AND Password = MD5("pass1")
i guess the problem is hackers can have a dictionary of common passwords hashed with MD5()
to find out user passwords? and just curious, they do this so they can find out which user uses which password? provided they got the user database? if i am wrong, what is the issue of using just MD5?
i think i need help understanding what is the problem with using MD5 only, then progressively, how does salts help, different hashing methods etc.
as i do not develop really secure apps, i also want to consider performance. i dont want a very secure but slow app :) so no need overkills, which will likely confuse me anyway
UPDATE
i dont a very basic example seeing of my logic of authenticating users with salts is right. basically, i need to get the salt of the user from the database using the username then do the actual authentication query right?
mysql_connect("localhost", "root");
mysql_select_db("test");
// simulate user entry
$username = "user1";
$password = "password1";
// get salt for username
$result = mysql_query("SELECT salt FROM users WHERE username = '$username'");
if ($row = mysql_fetch_assoc($result)) {
$salt = $row["salt"];
// actual authentication
$sql = "SELECT id FROM users WHERE username = '$username' AND password = '" . hash_hmac("sha256", $password, $salt) . "'";
$result = mysql_query($sql);
if ($row = mysql_fetch_assoc($result)) {
echo "login success. userid = " . $row["id"];
} else {
// wrong password
echo "login failed";
}
} else {
// wrong username
echo "login failed!";
}