Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------
- LOGIN CONTROLLER
- ------------------------------
- public function login()
- {
- $this->load->view('login');
- $this->load->model('user_model');
- $fetch = $this->user_model->login_user();
- if($fetch){
- $this->load->view('success');
- }
- else{
- $this->load->view('unsuccess');
- }
- }
- ------------------------------------------
- LOGIN MODEL
- ------------------------------------------
- public function login_user(){
- $password = $this->input->post('psw');
- $this->db->select('password');
- $this->db->from('user');
- $this->db->where('password', password_hash($password, PASSWORD_DEFAULT)); //hash pass
- $query = $this->db->get();
- $res = $query->result_array();
- if($this->isAccountExist() == false){
- if($query->num_rows() > 0){
- $_SESSION['userid'] = $res['user_id'];
- $_SESSION['logged'] = true;
- return true;
- }else{
- $_SESSION['message'] = "Incorrect username/password combination.";
- return false;
- }
- }else{
- $_SESSIOn['message'] == "Account doesn't exists.";
- return false;
- }
- }
- public function isAccountExist(){
- $username = $this->input->post('userid');
- $this->db->select('username');
- $this->db->from('user');
- $this->db->where('username', $username);
- $query = $this->db->get();
- if($query->num_rows() > 0){
- return true;
- }else{
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement