【发布时间】:2014-11-04 08:49:15
【问题描述】:
我有一个登录页面,用户在其中输入 ID 和密码。要重置密码,我必须检查输入的密码是否存在,是否与我输入的 ID 匹配。如何验证它。我无法来验证它。如果用户输入任何密码,则显示记录已更新。如何验证它。这是代码
登录.php
<label type="text" name="id" maxlength="50" size="20">ID</label><br />
<input type="text" name="id" placeholder="ID" class="input" size="20"/><br /></div>
<div class="formItem">
<label type="text" name="uid" maxlength="50" size="20">Password</label><br />
<input type="password" name="uid" placeholder="ID" class="input" size="20"/><br /></div>
<span class="field">(* Required field)</span><br /><br />
<input type="submit" name="login1" value="LOGIN" class="button"><br /><br /><br /><br />
</form>
</div>
</body>
</html>
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$db = "abc";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
mysql_select_db($db,$dbhandle) or die('cannot select db');
if(isset($_POST['login1']))
{
$id= $_POST['id'];
$uid= $_POST['uid'];
$query= "select * from resume where id='$id'
AND uid='$uid'";
$run= mysql_query($query);
if(mysql_num_rows($run)>0){
echo "<script>window.open('resetp.php','_self')</script>";
}
else {
echo "<script>alert('Login details are incorrect!')</script>";
}
}
?>
resetp.php
<label type="text" name="uid" maxlength="50" size="20">Old Password</label><br />
<input type="text" name="uid" placeholder="id" class="input" size="20"/><br /></div>
<div class="formItem">
<label type="text" name="uid" maxlength="50" size="20">New Password</label><br />
<input type="password" name="pass" placeholder="pass" class="input" size="20"/><br /></div>
<div class="formItem">
<label type="text" name="cpas" maxlength="50" size="20">Confirm Password</label><br />
<input type="password" name="cpas" placeholder="" class="input" size="20"/><br /></div>
<div class="formItem">
<input type="submit" name="login1" value="RESET" class="formButton"><br /><br /><br /><br /></div>
</form>
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$db = "resume1";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
mysql_select_db($db,$dbhandle) or die('cannot select db');
if(isset($_POST['login1']))
{
$pass= $_POST['pass'];
$uid= $_POST['uid'];
$cpas=$_POST['cpas'];
$query = "Update `resume` SET uid='".$_POST['pass']."' where uid='".$_POST['uid']."'";
$run = mysql_query($query);
if($query)
{
echo "<script>alert('Record updated')</script>";
}
else
{
echo "<script>alert('no')</script>";
}
}
?>
我如何验证它
【问题讨论】:
-
如果失败则无效。
-
Update resume SET uid='".$_POST['pass']."' where uid='".$_POST['uid']."'在这里您将uid设置为可能错误的密码(它可能会失败,因为您无法更新在 where 子句中使用的列)。此外,您还有很多安全问题。首先,您不会逃避用户输入,您应该始终这样做。其次,您将普通密码存储在数据库中。您至少应该使用像md5()这样的简单哈希来存储密码(但还有更好的方法,请尝试阅读有关加盐密码的内容)。 -
ya..我想验证旧密码是否相同,旧密码是否与表单中输入的相同。
-
接下来,您使用
if($query)而不是if($run)。由于查询是非空字符串,所以第一个始终为真。 -
你在哪里检查密码?还有大量的 SQL 注入。
标签: php mysql phpmyadmin