douzhun4124 2013-11-23 12:03
浏览 21
已采纳

我的网站容易受到sql注入吗? (PHP新手)

I'm new to php for about a month and I decide to create my own website. Situation: My mysql server store user as md5 and password as md5. And a captcha on the login page

Let's have a look at my code

<?php
session_destroy();
$usermod=md5($_POST["user"]);
$passmod= md5($_POST["pass"]);
if(file_get_contents("http://www.opencaptcha.com/validate.php?ans=".$_POST['code']."&img=".$_POST['img'])=='pass')
{
$con=mysqli_connect("hidden","hidden","hidden","hidden");
// Check connection
if (mysqli_connect_errno())
 {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result2 = mysqli_query($con,"SELECT * FROM Users
WHERE Username_login='$usermod'");
if($row2 = mysqli_fetch_array($result2))
{
$result = mysqli_query($con,"SELECT * FROM Users
WHERE Username_login='$usermod' AND Password='$passmod'");
if($row = mysqli_fetch_array($result))
{
echo "Thank you for logging in: ".$row['FirstName']." as ".$row['Username'];
session_start();
$_SESSION['user'] = $row['Username'];
$_SESSION['email'] = $row['Email_start']."@".$row['Email_domain'];
$_SESSION['name'] = $row['FirstName']." ".$row['LastName'];
header("Location: http://mspb.tk/login/welcome.php");
}
else
{
header("Location: http://mspb.tk/login/login.php?login=failed");
}}
else
{
header("Location: http://mspb.tk/login/login.php?username=failed");
}
}
else {
header("LOCATION:http://www.mspb.tk/login/login.php?opencaptcha=failed");
}
?>

That's it if anyone spot an sql injection and tell me I would be very happy :) Thank you very much Poom

  • 写回答

3条回答 默认 最新

  • dongshun1884 2013-11-23 12:08
    关注

    No, it's not vulnerable to SQL injection, however...

    There are a bunch of other security-related issues to note:

    1. You are using MD5 to store passwords. MD5 is known to be weak and inexpensive to crack, and you should use PHP's password_hash function instead. If you're unable to use PHP 5.5 due to using shared hosting etc. look up crypt with CRYPT_BLOWFISH & generating random salts.
    2. You are not salting passwords. By using a salt (a random string generated for each user record stored alongside the password in the database), you can make it far more difficult for a cracker to break the hashes in your database as even two identical passwords will produce different hashes. You also remove the rainbow table attack vector. If you use password_hash, this is done for you.
    3. You appear to be using MD5 to store usernames, there is no reason to do this just to avoid SQL injection, learn to use prepared statements instead as later functions (like search, for example) will require you to submit plaintext parameters for comparison against plaintext.
    4. It looks like you've just dumped your hostname and MySQL username/password on StackOverflow. I'd suggest changing those on your live site immediately as someone could have copy/pasted them before you hid them.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?