Люди могут войти с паролями даже других пользователей.Я не могу понять, что я делаю не так.
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;
}