booxvid Posted September 30, 2012 Share Posted September 30, 2012 (edited) Here's the snippet code in controller: public function me_login(){ $this->load->view('header'); $this->form_validation->set_rules('username','First Name','required'); $this->form_validation->set_rules('password','Last Name','required'); $this->form_validation->set_error_delimiters(' ',''); if($this->form_validation->run()==FALSE){ $this->load->view('view_login'); } else{ $u= $this->input->post('username'); $p= $this->input->post('password'); $username = trim($u); $password = trim($p); //search same info from db $boolean = $this->blog_model->login($username,$password); if($boolean){ $userdata = array( 'username' => $username, 'logged_in' => TRUE ); $this->session->set_userdata($userdata); echo ""; $this->load->view('view_home',$userdata); } else{ echo ""; $this->load->view('view_login'); } } } here's my blog_model where my login function located: public function login($username,$password){ $encode = $this->encrypt->encode($password); $query = $this->db->get_where('blog_user', array('username' => $username, 'securepass' => $encode)); return $query->result(); } I don't know why my Login function will always be failed. Edited September 30, 2012 by booxvid Quote Link to comment https://forums.phpfreaks.com/topic/268927-login-form-with-codeigniter/ Share on other sites More sharing options...
Mahngiel Posted October 1, 2012 Share Posted October 1, 2012 Foremost, I don't understand your usage with the 'error deliminators' - are you expecting to use newlines? This: $u= $this->input->post('username'); $p= $this->input->post('password'); $username = trim($u); $password = trim($p); Can be replaced with: $this->form_validation->set_rules('username','First Name','required|trim'); $this->form_validation->set_rules('password','Last Name','required|trim'); Now, in order to determine why it's failing, I suggest you query for the username that matches the input value and echo out the password in its row AND the hashed POST value. If the two do not match, then you need to figure out where the problem starts. Quote Link to comment https://forums.phpfreaks.com/topic/268927-login-form-with-codeigniter/#findComment-1381993 Share on other sites More sharing options...
hell_yeah Posted November 4, 2012 Share Posted November 4, 2012 In addition to Mahngiel's suggestions, in your login function, since you only need to check if the user name is valid or not and not using the data, you can do something like this instead of returning the whole data public function login($username,$password){ $encode = $this->encrypt->encode($password); $query = $this->db->get_where('blog_user', array('username' => $username, 'securepass' => $encode)); if ($query->num_rows() == 1){ return TRUE; }else{ return FALSE; } } Quote Link to comment https://forums.phpfreaks.com/topic/268927-login-form-with-codeigniter/#findComment-1390073 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.