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

时间:2015-10-28 11:03:42

标签: php class oop login

我的登录功能有什么问题?

这在“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);
    }
  }

这是我使用的函数hashData()(也在同一个类中定义):

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

这就是我尝试使用该函数的方法(此网站包含的类包含require_once('auth.php'))

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

0 个答案:

没有答案