dongyaofu0599 2016-03-23 08:49
浏览 56

安全注册,使用hash()登录

<?php 
$conn=mysqli_connect("localhost", "root", "","users");

if (!$conn) {
    echo "Bad connection!!!";
}

        $user_name=$_POST['user_name'];
        $user_password=$_POST['user_password'];


$sql_check=mysqli_query($conn, "SELECT user_name, password FROM user_info WHERE user_name='$user_name' AND password='$user_password'") or die("Bad sql query");

if (mysqli_num_rows($sql_check)>0) {
    echo "user exists";
}



else {
    $sql_insert=mysqli_query($conn, "INSERT INTO user_info (id, user_name, password) VALUES (null,'$user_name', '$user_password')");
    echo "New user added!!!";
}
 ?>

 <!DOCTYPE html>
 <html>
 <head>
    <title></title>
 </head>
 <body>



<form method="POST" action="pdo_konekcija.php">
<input type="text" name="user_name">
<input type="password" name="user_name">
<input type="submit" name="btn_submit" value="REGISTER">
</form>


 </body>
 </html>

I have basic form for user registration. I can't figure best way for checking if the user exists or not, so if not I want to register new user as you can see from sql statements. How can I include hash() for password for the user_password field? Both fields must be filled for checking and registering process. Can I use this kind of mysql I procedural way for preventing sql injection or not? I am building register/login from scratch so need help, thank you all.

  • 写回答

2条回答

  • douyi2798 2016-03-23 08:52
    关注

    For checking if a users password matches, first check the user exists and retrieve their password hash, then run it through your hash verification function afterwards.

    In answer to your second question, yes your current system is vulnerable to SQL injection.

    评论

报告相同问题?

悬赏问题

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