他のユーザーのパスワードでもログインできます。私は何が間違っているのか理解できません。このCodeIgniterログインスクリプトの重大な問題
function login()
{
$this->form_validation->set_rules('username','Username','trim|xss_clean|required|callback_login_user_check');
$this->form_validation->set_rules('password','Password','trim|xss_clean|required|min_length[4]|max_length[20]|callback_password_check|sha1');
$this->_username = $this->input->post('username');
$this->_password = $this->_salt.sha1($this->input->post('password'));
if($this->form_validation->run() == FALSE)
{
$toView['title']= 'Please login';
$this->build_content($toView);
$this->render_page();
}
else
{
$this->account_model->login();
//$data['message'] = "You are logged in! Now go to ". anchor("members/dashboard","Dashboard");
redirect('members/dashboard');
}
}
//---------------------------------------------------------------------------------------------------------------------------
// password CHECKING
function password_check(){
$this->db->where('username', $this->_username);
$this->db->where('password', $this->_password);
$query = $this->db->get('users');
$result = $query->row_array();
if ($query->num_rows() == 0)
{
$this->form_validation->set_message('password_check','There was an error! ');
return FALSE;
}
if($result['password'] == $this->_password)
{
return TRUE;
}
}
function login_user_check($user)
{
$query = $this->db->get_where('users', array('username'=>$user));
if(!$query->num_rows()>0)
{
$this->form_validation->set_message('login_user_check', 'The %s does not exists in our database');
return FALSE;
}
if($query->num_rows() > 0)
{
foreach($query->result_array() as $row)
{
//$data[$row['id']] = $row['name'];
$this->session->set_userdata('user_id', $row['user_id']);
}
}
$query->free_result();
return true;
}
あなたが正確に何だと思いますが達成されていますあなたは 'where'を2回連続で呼んでいますか? –
私は専門家ではありませんが、2つの$ this-> db-> ORまたはANDで句を組み合わせるのですか? – Dennis
[documentation](http://codeigniter.com/user_guide/database/active_record.html#where): '$ this-> db-> where( 'name'、$ name); $ this-> db-> where( 'title'、$ title); $ this-> db->ここで( 'status'、$ status); // WHERE name = 'Joe' AND title = 'boss' AND status = 'active''私の人生を保存するためにデータベースに問い合わせる難しい方法を考え出すことができません:P – Esailija