drazvzi741287 2015-10-28 11:03
浏览 16

外部类的登录功能不起作用

What is wrong with my login function?

This is defined in the class 'Auth':

public function login($username,$password)
{
  $loggedin = false;
  $password = $this->hashData($password);
  $query = "SELECT `Username`, `PWhash` FROM 'user' WHERE 'Username' = '$username'LIMIT 1";

  if ($result = mysqli_query($db, $query)){

    while ($obj = mysqli_fetch_object($result)){
      $dbuser = $obj->Username;
      $dbpwd = $obj->PWhash;

      if ($dbpwd == $password){
        $loggedin = true;
      }
      else{
        $loggedin = false;
        exit;
      }
      mysqli_free_result($result);
    }
  }

This is the function hashData() that I used (also defined in the same class):

protected function hashData($data){
  return hash_hmac('sha512', $data);
}

This is how I tried to use the function (class included in this site with require_once('auth.php'))

$var = new Auth; // instantiating ... seems to work fine
$var->login($username, $password); // this does not work
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数