Welcome Guest, Not a member yet? Register   Sign In
Where should the authentication function go?
#2

[eluser]bloodagar[/eluser]
Update: Got it resolved! I changed
Code:
$this->db->get('users')
to
Code:
$this->db->get('users')->result_array()
in the if condition. Yay! Smile

Quote:Also I got another problem, whatever I type in the username/password inputs it allows me to view the secure area. Here's the code:

the model
Code:
<?php

class MLogin extends Model {
    
    function MLogin()
    {
        parent::Model();
    }
    
    function login($user, $pass)
    {
        $this->db->where('username', $user);
        $this->db->where('password', $pass);
        if ($this->db->get('users')) {
            $this->session->set_userdata('logged_in', TRUE);
            return TRUE;
        } else {
            return FALSE;
        }
    }
    
    function logged_in()
    {
        if ($this->session->userdata('logged_in')==TRUE) {
            return TRUE;
        } else {
            return FALSE;
        }
    }
    
}

?>

the controller
Code:
<?php

class Login extends Controller {
    
    function Login()
    {
        parent::Controller();
        $this->load->scaffolding('users');
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->model('mlogin');
    }
    
    function index()
    {
        $data['error'] = "";
        $user = $this->input->post('username');
        $pass = $this->input->post('password');
        if ($user) {
            if ($this->mlogin->login($user, $pass)) {
                redirect('login/secure', 'refresh');
            } else {
                $data['error'] = "Incorrect username/password";
                $this->load->view('login', $data);
            }
        } else {
            $this->load->view('login', $data);
        }
    }
    
    function secure()
    {
        if ($this->mlogin->logged_in()) {
            $this->load->view('secure');
        } else {
            redirect('login', 'refresh');
        }
    }
    
}


?>

I'd also appreciate of you guys have any suggestion/comments about my codes. Thank you very much!


Messages In This Thread
Where should the authentication function go? - by El Forum - 10-19-2008, 07:27 PM
Where should the authentication function go? - by El Forum - 10-19-2008, 07:51 PM
Where should the authentication function go? - by El Forum - 10-19-2008, 08:57 PM
Where should the authentication function go? - by El Forum - 10-19-2008, 08:59 PM
Where should the authentication function go? - by El Forum - 10-19-2008, 09:33 PM
Where should the authentication function go? - by El Forum - 10-19-2008, 09:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB