管理员的登录名/密码,存储在数据库中,在表中admin
。进入“管理面板”时,有一个验证脚本可以检查它们的正确性。我不知道如何从数据库中传输数据并将其提供给验证器进行验证。这是一个脚本:
public function loginValidate()
{
$params = [
'login' => $admin['login'],
'password' => $admin['password'],
];
$admin = $this->db->all('SELECT * FROM `admin` WHERE login = :login AND password = :password', $params);
/*Это я глядел чего в переменных хранится
echo 'POST '; print_r($_POST);
echo '<br />';
echo 'admin '; print_r($admin);
echo '<br />';
echo 'admin '; print_r($admin['login']);
echo '<br />';
echo 'admin '; print_r($admin['password']);
echo '<br />';*/
if ($admin['login'] != $_POST['login'] or $admin['password'] != $_POST['password']) {
$this->error = 'Login incorrect!';
return false;
}
return true;
}
这是结论:
Notice: Undefined variable: admin in /models/AdminModel.php on line 28
Notice: Trying to access array offset on value of type null in /models/AdminModel.php on line 28
Notice: Undefined variable: admin in /models/AdminModel.php on line 29
Notice: Trying to access array offset on value of type null /home/max/www/test/application/models/AdminModel.php on line 29
Notice: Undefined index: login in /models/AdminModel.php on line 42
{"status":"error","message":"Login incorrect!"}
这是故意输入错误的用户名/密码的结果。
问题是这样解决的:
public function loginValidate()
{
$password = $this->db->col('SELECT * FROM `admin`');
if (!password_verify($_POST['password'], $password)) {
$this->error = 'Login incorrect!';
return false;
}
return true;
}