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.

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集