Passing two values to custom validation

#1
[eluser]Unknown[/eluser]
Hi,

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.

thanks
a

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

You would make a checkLogin function that looks like this:
Code:
function checkLogin($pw)
    {
        $this->load->model('User_model');
        
        $un = $this->input->post('username');
        
        if($this->User_model->checkCredentials($un, $pw))
        {
            $this->session->set_userdata('logged_in', TRUE);
            return true;
        }
        else
        {
            $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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.