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

I am not able to compare my password with md5 database password

我正在尝试将我的登录密码与数据库 md5 密码进行比较,但做不到 it.I 我也使用 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";

请尝试 if($numrows!=0) 而不是 if($numrows!==0)

试试这个...

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

删除循环中的以下行:

 $dbusername;
 $dbpassword;

试试这个:

$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";

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