CodeIgniter Forums

Full Version: Validation Inquiry
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]stevefink[/eluser]
Hi all,

Having a blast building my application -- looks like you're stuck with me using Code Igniter. *snicker*

Quick inquiry. I'm using a callback function for a custom validation. I need to make a database query to verify if a user's password has been properly passed in. I'm sure almost everyone here has already done this. Is there anyway to pass the 'clean, xss free, username validated string' also to the callback function .. in addition to the password string? This way I can avoid checking it twice. Also prefer not making it a global variable, but that would probably be more efficient than what I'm doing now either way.

Here's a snippet of my code:

--

Code:
function index()
    {
        $rules['user'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
        $rules['password'] = "trim|required|md5|callback_check_password";
                // some more stuff, etc
        }
        
            function check_password($str_pass)
    {
        $name = $this->input->post('user');
        xss_clean("$name");
        $sql = "SELECT id FROM users where name = ? AND password = ?";
        $is_valid_login = $this->db->query($sql, array("$name", "$str_pass"));
        
        if($is_valid_login->num_rows > 0)
        {
            return TRUE;
        }
        else
        {
            $this->validation->set_message('check_password', 'Incorrect login.');
            return FALSE;
        }
    }

--

Thanks for taking a look, all. :-) The code above works, I'd just like to start coding with better practice in mind.

Cheers!

- sf

El Forum

[eluser]Michael Wales[/eluser]
See this post