Welcome Guest, Not a member yet? Register   Sign In
Passing two values to custom validation


was just looking at some validation code I have on a login form, and it seemed like it could be cool to test whether the login/password combination provided was valid, and I wanted to do this inside a custom validation callback.

Any clever ways of doing this that spring to mind? It's a security-light internal thing so I don't want to install and configure auth packages just for this.


[eluser]Pascal Kriete[/eluser]
It's pretty simple - if your validation looks like this:
$rules['username'] = "trim|required|max_length[20]|xss_clean";
$rules['password'] = "required|callback_checkLogin";

You would make a checkLogin function that looks like this:
function checkLogin($pw)
        $un = $this->input->post('username');
        if($this->User_model->checkCredentials($un, $pw))
            $this->session->set_userdata('logged_in', TRUE);
            return true;
            $this->validation->set_message('checkLogin', 'Credentials do not match.');
            return false;
Then in your internal pages you would check if the session data is set to true - and if it isn't you would redirect.

Theme © iAndrew 2016 - Forum software by © MyBB