How to write a secure username & password verification in PHP ?
I use MD5 for password ($pass) and string for username ($name) and write this code in PHP for user account verification.
$post_vars = $_POST;
if (isset($post_vars['name']))
{
$name = $post_vars['name'];
$pass = md5($post_vars['pass']);
$dbConn = db_open();
$sql = "select `password` from `user_table` where `user_name` = '$name' limit 1;";
echo $sql;
$sth = $dbConn->prepare($sql);
$sth->execute();
$row = $sth->fetch();
if ($row !== false)
{
$verify = $row['password'];
if ($pass == $verify)
{
$_SESSION['isLoggedIn'] = true;
header('Location: ' . _DEBUG_URL_);
}
else $iframeURL = _LIB_URL_ . 'accessdenied.htm';
}
else echo 'No results found!';
}
Is this query hackable by method of SQL Injection, and how it can be hacked ? I use PDO for MySQL.
"select `password` from `user_table` where `user_name` = '$name' limit 1;"