Welcome Guest, Not a member yet? Register   Sign In
Using Validation Class to validate Username and Password
#1

[eluser]chadsaun[/eluser]
I'm new to Codeigniter and need some help to figure out the best way to validate the username and password.

This is what I have so far, but I want to setup some validation rule for validating if the username and password were found in the DB so that if it wasn't they'll see an error message.

Code:
function authorize() {
        $this->form_validation->set_rules('username', 'Username', 'trim|required|max_length[50]|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|max_length[50]');
        
        $authenticated = false;
        
        $query = $this->db->get_where('safety_users', array('username' => $_POST['username'], 'password' => $_POST['password']));
        if ($query->num_rows() > 0) {
            $authenticated = true;
        }
        
        if ($this->form_validation->run() == false || !$authenticated) {
            $this->load->view('login_view');
        } else {
            $this->load->view('products_view');
        }
    }


Messages In This Thread
Using Validation Class to validate Username and Password - by El Forum - 02-18-2009, 02:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB