I want to change my register/login pages from md5 to bcrypt. The register part is allright but I can't get the login part working good. I am trying to work with a bcrypt library;https://github.com/ircmaxell/password_compat/blob/master/lib/password.php.
The original login function(without md5) looks like this;
function login($username, $password) {
$user_id = user_id_from_username($username);
$username = sanitize($username);
return (mysql_result
(mysql_query
("SELECT COUNT(`user_id`)
FROM `users`
WHERE `username` = '$username'
AND `password` = '$password'"), 0) == 1) ? $user_id : false;
}
What I am trying to do is retrieve the database but with the original code is is not possible because of the mysql_result part. I thought for example that;
function login($username, $password) {
$username = sanitize($username);
$user_query = mysql_query("SELECT `password` FROM `users` WHERE `username` = '$username'");
$row = mysql_fetch_assoc($user_query);
$hash = $row['password'];
password_verify($password, $hash);
}
would solve this problem, but it isn't.
Is there a solution without mysql_fetch_assoc() here or am I trying to retieve the database wrong?