我无法将我的密码与md5数据库密码进行比较

时间:2015-04-08 05:32:11

标签: php md5

我试图将我的登录密码与数据库md5密码进行比较,但无法做到。我也使用md5制作了我的登录密码,但问题仍然存在..请帮助我,我是PHP的新手。     

$username = $_POST['username'];
$password = $_POST['password'];
$pass =md5($password);
if ($username&&$password)
{
$connect = mysqli_connect("localhost", "root", "pixster")or die("Couldn't connect to database!");
mysqli_select_db($connect,'rdb') or die ("Couldn't find database");
echo "successfully connected to database<br>";
$query = mysqli_query($connect,"SELECT * FROM login WHERE uname ='$username'");
$numrows=mysqli_num_rows($query);
if($numrows!==0)
{
   while($row = mysqli_fetch_assoc($query))
   {
   $dbusername = $row['uname'];
   $dbpassword = $row['password'];
   $dbusername;
   $dbpassword;
   }

    if($username==$dbusername&& $pass==$dbpassword)
    {
       include('logprofile.php');
       echo "you are logged in!";
       //$_SESSION['abc'] = $username;


    }else

    echo "your password is wrong";

4 个答案:

答案 0 :(得分:0)

请尝试使用if($numrows!=0)代替if($numrows!==0)

答案 1 :(得分:0)

试试这个......

    while($row = mysqli_fetch_assoc($query))
       {
       $dbusername = $row['uname'];
       $dbpassword = $row['password'];
       }

在循环中删除以下行:

 $dbusername;
 $dbpassword;

答案 2 :(得分:0)

试试这个:

$username = $_POST['username'];
$password = $_POST['password'];
$pass =md5($password);
if ($username&&$password)
{
$connect = mysqli_connect("localhost", "root", "pixster")or die("Couldn't connect to database!");
mysqli_select_db($connect,'rdb') or die ("Couldn't find database");
echo "successfully connected to database<br>";
$query = mysqli_query($connect,"SELECT * FROM login WHERE uname ='$username'");
$numrows=mysqli_num_rows($query);
if($numrows > 0)
{
   while($row = mysqli_fetch_assoc($query))
   {
   $dbusername = $row['uname'];
   $dbpassword = $row['password'];
   }

    if($username==$dbusername && $pass==$dbpassword)
    {
       include('logprofile.php');
       echo "you are logged in!";
       //$_SESSION['abc'] = $username;


    }else

    echo "your password is wrong";

答案 3 :(得分:0)

我得到了这个问题的答案。有一个数据库问题我的密码长度比md5转换密码短。所以我只是增加了长度。现在两个密码都匹配,我可以登录。