更新表

时间:2016-07-10 08:01:37

标签: php password-hash

我的登录系统md5哈希用户名,密码是密码。因此我无法根据用户名获取行?我的客户端然后输入一个我base6encode的电子邮件地址。然后我提供丢失的密码更改选项。但是,当我使用相同类型的哈希更新字段但使用电子邮件字段作为标识符时,新密码不正确? 下面是我的更新样本,但硬编码用于说明(PS这也不起作用?)。

$em = 'example@example.com';
$em1 = base64_encode($em);
$ps = 'some password';
$password_hash = password_hash($ps,  PASSWORD_BCRYPT);
$qu = "UPADTE table SET field = '$password_hash' WHERE email = '$em1'";
$res = mysqli_query($link, $qu);

在验证用户存在并为其发送电子邮件以确定自己是帐户所有者之后,编辑问题以包含我的代码。这是最终的处理器页面。

if(EMPTY($_POST[psw1]) ) { 
echo "New password must be supplied"; } 
elseif(EMPTY($_POST[psw2]) ) { 
echo "Repeat password must be entered"; } 
elseif($_POST[psw1] != $_POST[psw2]) { 
echo "Passwords entered do not match";
} elseif(EMPTY($_POST[eu])) { 
echo "Essential data is missing in order to complete this process.";
} 
elseif (strlen($_POST['psw1']) < 6) {
echo  "Password must be at least six characters in length";
     } 
elseif (preg_replace("/[^a-zA-Z0-9]/", "", $_POST['psw1']) !=      $_POST['psw1']) {
echo "Password may only contain letters and numbers";
    } 
elseif(!EMPTY($_POST[psw1]) && !EMPTY($_POST[psw2]) && !EMPTY($_POST[eu]) && $_POST[pw1] == $_POST[pw2] ) { 

include "conn.php";
echo "$_POST[eu]<br />";
$eu = $_POST[eu];
$pdw = password_hash($_POST[pw1], PASSWORD_BCRYPT);

$sq = mysqli_query($link, "UPDATE str1 SET pf = '$pdw', cu_pw_status =    '2' WHERE cu_type = '$eu'");
echo "Your password has been changed, you may now login <a    href='login2.php'>Login</a>";
} else { 

echo&#34;发生错误。联系网站管理员&#34 ;; }

1 个答案:

答案 0 :(得分:1)

  1. 检查您的users表中是否有列'field'。似乎怀疑。
  2. 检查您的更新字符串,现在它错过了表名。
  3. 在更新之前检查您是否有用户:

    $exists = mysqli_query("SELECT id FROM users WHERE email='$em1');
    
    if (!is_empty($exists)) {
    
        mysqli_query("UPDATE TABLE users SET password = '$ps' WHERE id='$exists');
    
        echo 'updated' . "\n";
    
    } else {
    
      echo 'no user with such email hash' . "\n";
    }