I've been working on a site that requires users to login. It's written in PHP with MySQL, and passwords are stored as Whirlpool hashes with a salt (source code later).
However, security sites or fellow developers have advised against this (actually, SHA-256, but the point remains) and have recommended bcrypt or PBKDF2. I'm not sure of the advantages of using one of these or why the current one is wrong. Does anybody mind explaining their reasoning?
Here's my code to register:
$escusrnm = $con->real_escape_string($_POST["usrnm"]);
$newSalt = substr(str_shuffle(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ),0, 1) . substr(str_shuffle(aBcEeFgHiJkLmNoPqRstUvWxYz0123456789),0, 31);
$passHashed = hash("whirlpool", $_POST["pss"].$newSalt);
$con->query("INSERT INTO users (username, pass, hash) VALUES ('{$escusrnm}', '{$passHashed}', '{$newSalt}')");
$_SESSION["usernm"] = $_POST["usrnm"];
Here's my login code:
$escusrnm = $con->real_escape_string($_POST["usrnm"]);
$getdats = $con->query("SELECT * FROM users WHERE username='{$escusrnm}'");
if (mysqli_num_rows($getdats) > 0) {
$getdats = $getdats->fetch_assoc();
if(hash("whirlpool", $_POST["pss"].($getdats["hash"])) == $getdats["pass"]) {
$_SESSION["usernm"] = $getdats["username"];
} else {
$errormsg = "There was an error. Check your information again, or register.";
}
} else {
$errormsg = "There was an error. Check your information again, or register.";
}