Php Codeigniter form_验证未验证
我目前正在处理我的登录表单。昨天我登录时,即使凭据错误,它也会让我登录,因此我在我的模型中将此代码的Php Codeigniter form_验证未验证,php,forms,codeigniter,validation,login,Php,Forms,Codeigniter,Validation,Login,我目前正在处理我的登录表单。昨天我登录时,即使凭据错误,它也会让我登录,因此我在我的模型中将此代码的=更改为= public function can_log_in() { $sql ="SELECT * FROM tbl_users WHERE USERNAME = ? AND PASSWORD = ?"; $data1 = array( 'USERNAME' => $this->input->post('USERNAME'),
=
更改为=
public function can_log_in() {
$sql ="SELECT * FROM tbl_users WHERE USERNAME = ? AND PASSWORD = ?";
$data1 = array(
'USERNAME' => $this->input->post('USERNAME'),
'PASSWORD' => $this->input->post('PASSWORD')
);
$query = $this->db->query($sql, $data1);
if ($query->num_rows == 1) {
return true;
} else {
return false;
}
}
现在,即使凭据正确,它也不会登录。这是我的控制器:
public function loginValidate() {
$this->load->library('form_validation');
$this->form_validation->set_rules('USERNAME','Username','required|trim|callback_validateCreds');
$this->form_validation->set_rules('PASSWORD','Password','required|trim');
if ($this->form_validation->run() == FALSE) {
$this->index();
} else {
$data = array(
'USERNAME' => $this->input->post('USERNAME'),
'is_logged_in' => 1
);
$this->session->set_userdata($data);
redirect('login/adminIndex');
}
}
public function validateCreds() {
$this->load->library('form_validation');
$this->load->model('login_model');
if($this->login_model->can_log_in()) { // can_log_in() model
return true;
} else {
$this->form_validation->set_message('validateCreds','Username and password did not match.'); //return message to validateCreds
return false;
}
}
在问题模型函数中靠近
if($query->num\u rows==1)
如果($query->num_rows()==1),您可以这样更改
模型函数中的完整代码
public function can_log_in(){
$sql ="SELECT * FROM tbl_users WHERE USERNAME = ? AND PASSWORD = ?";
$data1 = array(
'USERNAME' => $this->input->post('USERNAME'),
'PASSWORD' => $this->input->post('PASSWORD')
);
$this->db
$query = $this->db->query($sql, $data1);
if ($query->num_rows() == 1){
return true;
}else{
return false;
}
通常密码是加密的,你考虑过吗?是的。我刚刚取消了加密,这样我就可以更容易地发现是否有错误或信用是错误的。