我正在尝试使用我的登录脚本。它使用随机盐和盐; MD5。目前只需键入有效的用户名并按下没有密码的提交即可验证用户身份。 (我知道md5不安全,以后会转移到brcrypt,但需要先让它工作)
无法看到错误 - 任何帮助都非常感激。
if(!empty($_POST)) {
$user = isset($_POST['username']) ? $G['db']->escape($_POST['username']) : "";
$pass = isset($_POST['password']) ? md5($G['db']->escape($_POST['password'])) : "";
$account = $G['db']->queryUniqueValue("SELECT username,salt,password,uid FROM `".$C['db']['table']."` WHERE `username` = '$user'");
//User exists
if($G['db']->numRows()==1) {
//If the password is right
if(md5($account['salt'].":".md5($pass))) {
//Validate the user
$G['login']->validateUser(array("username"=>$account['username'], "id"=>$account['uid'], "utype"=>$account['utype']));
//User Validated redirect them
header("Location: ./?e=validpage");
} else {
答案 0 :(得分:2)
if(md5($account['salt'].":".md5($pass)))
嗯......这会在数据库中创建salt的MD5哈希值并输入密码。并将其与...... true
进行比较。任何非空字符串都是true
。所以这个条件读取如果输入的密码连同盐哈希值到任何非空字符串(每次都会这样),让用户进入。
您可能打算做以下事情:
if (md5($account['salt'] . ':' . md5($pass)) === $account['password'])
^^^^^^^^^^^^^^^^^^^^^^^^