dongshungou7699 2014-08-15 08:27
浏览 40

现有用户的密码_hash [关闭]

I get a PHP Error and returning empty body on hurl.it. Im trying to hash the password of existing users in my DB.

using user_id as POST and update it to my DB in a new created column

// Create connection
$con = mysqli_connect($dbPath,$dbUserName,$dbPassword,$dbSchema);

// Check connection
if (mysqli_connect_errno()) {
  $error = "DB connection error";
}

$user_id = $_POST['user_id'];  


//exisitng password
$sql = mysqli_query($con, "SELECT password FROM user_table 
                            WHERE user_id = '$user_id'");

if(!$sql) $error = "SELECT user_table error";

$i=0;
while($result = mysqli_fetch_assoc($sql)){

    $hash[$i] = $result;

    if($hash[$i]) {
        $check_hash = password_hash($hash[$i], PASSWORD_DEFAULT);

        //store into DB
        $result2 = mysqli_query($con, "INSERT INTO user_table (password_secure) VALUES   ('$check_hash')"); 
    }
    $i++;
}



if(!$result2) $error = "INSERT user_table error";
// Set returns
if (!$error) $status = "successful";
  • 写回答

2条回答 默认 最新

  • douchengchu8374 2014-08-15 08:32
    关注

    There are many problems in your code, but the main culprit is the fact that you use INSERT when you should really be using UPDATE:

    UPDATE user_table SET password_secure=? WHERE user_id=?
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作