【发布时间】:2015-06-29 20:48:30
【问题描述】:
我是网站设计的新手,我最近做了一个网站,我想添加一个重置密码功能,它不起作用。
SQL 连接在 init.php 文件中
<?php
include('core/init.php');
include('includes/overall/header.php');
echo "
<h1>Reset Password</h1>
<div class='Reset' align='center'>
<form action='forgot_pass.php' method'POST'>
Enter your username<br><input type='text' name='username'><p>
<br>
Enter your email<br><input type='email' name='email'><p>
<input type='submit' value='Submit' name='submit'>
</form>
</div>
";
if (isset($_POST['submit']))
{
$username = $_POST['username'];
$email = $_POST['email'];
$query = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
$numrow = mysql_num_rows($query);
if ($numrow!=0)
{
while($row = mysql_fetch_assoc($query))
{
$db_email = $row['email'];
}
if ($email == $db_email)
{
$code = rand(10000,1000000);
$to = $db_email;
$subject = "Password Reset";
$body = "
Automated email. Click the link
http://random-html-stuff.webege.com/forgot_pass.php?code=$code&username=$username
";
mysql_query("UPDATE users SET passreset='$code' WHERE username='$username'");
mail($to,$subject,$body);
echo "Check Email";
}
else
{
echo "Email not correct";
}
} else {
echo "That user does not exist";
}
}
?>
如果有人可以帮助我,我会很高兴谢谢
【问题讨论】:
-
定义“它不起作用”。
-
您可以使用此代码进行 SQL 注入。每当您将用户输入直接传递给查询时,您就可以打开数据库以使其被操纵/公开意味着安全的数据。
-
如果可以的话,你应该stop using
mysql_*functions。它们不再被维护并且是officially deprecated。改为了解 prepared statements,并考虑使用 PDO,it's really not hard。 -
不要向他们索要电子邮件。只需询问用户名,然后使用数据库中的电子邮件。
-
您很容易受到sql injection attacks 的攻击,所以请尽情享受您的服务器 pwn3d。