我已经做了足够的研究,登录时它不会将我重定向到资源页面,以防密码正确。我之前尝试过密码的 SHA1,但首先处理更简单的情况,我删除了它。当我问 NAME = '$usr',因为我有用户作为用户名,如果我也输入用户,它不会显示错误的用户名,如果我们尝试这个,在终端上,对于用户名 'user' 或 'User',它显示一样。
<?php
$con = mysql_connect("localhost","root","*****");
session_start();
if(isset($_POST['submit1']))
{
if (!$con)
{
die("OOPS!Could not connect to server".mysql_error());
}
$passwd = $_POST['password'];
$usr=$_POST['username'];
mysql_select_db('USERS',$con) or die(mysql_error());
$result = mysql_query("SELECT PASSWD FROM USERS WHERE USERNAME='$usr'",$con) Or die(mysql_error());
$pass = mysql_result($result,0);
if ($pass==$passwd) {
header('Location : resource.html');}
else
{echo "sorry $usr wrong username or password"; }
}
else if(isset($_POST['submit2']))
{
$usr = $_POST['user'];
$passwd = $_POST['password1'];
$name = $_POST['fullname'];
mysql_select_db('USERS',$con) or die(mysql_error());
$result = mysql_query("SELECT * FROM USERS WHERE USERNAME='$usr'",$con) Or die(mysql_error());
$num = mysql_num_rows($result);
if ($num==0) {
mysql_query("INSERT INTO USERS(NAME,USERNAME,PASSWD) VALUES('$name','$usr','$passwd')");
echo "congrats! you have been added.Go back to resources and log in";
}
else echo "Someone already has that username. Go back and try with another username";
}
mysql_close($con);
?>