1

我在 codeigniter 中使用 phpass 登录。但是无法登录,出现已知错误我不确定是什么。用户名和密码正确。我的系统文件夹中有库用户,因为我使用了多个 ci 安装。我只是不确定为什么不让我登录。即使用户名和密码正确

目前知道错误正在显示。

库文件

public function __construct() {

$this->CI =& get_instance();
$this->CI->load->database();
// Libraries
$this->CI->load->library('session');
$this->CI->load->library('security/rwdsecurity');
// Models
$file = dirname(FCPATH) . '/admin/application/modules/backend/models/user/user_model.php';
$file = dirname(FCPATH) . '/install/application/modules/setup/models/install_model.php';

if(file_exists($file)) {
return true;
} else {
echo "Can't find file located in: " . $file;
}
}

public function login($username, $password) {
$username = $this->CI->db->where('username', $this->CI->input->post('username'));
$password = $this->CI->db->where('password', $this->CI->input->post('password'));
$user_query = $this->CI->db->get('user');

if($user_query->num_rows() ==  1) {
$data = array(
'username' => $this->CI->input->post('username'),
'isLogged' => true
);

$this->CI->sessions->set_userdata('user', $data);
$this->CI->rwdsecurity->check_password($password, $stored_hash);
return true;
} else {
return false;
}
}

控制器

public function index() {
    if($this->session->userdata('isLogged') == false) {
$this->login();
} else {
redirect('dashboard');
}
}

function login_credentials() {
$this->form_validation->set_rules('username', 'Username', 'required|trim|min_length[3]|max_length[12]|xss_clean|callback_validate');
$this->form_validation->set_rules('password', 'Password', 'required|trim');

if ($this->form_validation->run($this) == false) {
$data['action'] = site_url('login/login_credentials');
$this->load->view('template/common/login', $data);

} else {
$is_valid = $this->user->login($username, $password);

if($is_valid) {

$data = array(
  'username' => $username,
  'isLogged' => true
);

$this->session->set_userdata($data);
}

 redirect('dashboard');
}
}

function validate($username, $password) {
if($this->user->login($username, $password)) {
return true;
} else {
$this->form_validation->set_message('validate', "Incorrect Username Or Password");
return false;
}
}
4

0 回答 0