Welcome Guest, Not a member yet? Register   Sign In
Question about callback function
#1

[eluser]lennierb5[/eluser]
Alright,

I am VERY new to codeigniter but I have been playing around with the validation class, specifically with regards to logging a user in.

The problem I have is when I run my check_login function it does not md5 the passwd as set in the rules, I have to manually md5 it for it to work properly.

The below example DOES work but I am wondering why I cannot simply use $this->validation->passwd.

With using this example I am not sure if the passwd field is going through the xss_clean (which I set to go through all post data in the config)

Any advice on how to do this better or something I am missing?

Thanks!

Code:
function check() {
    $this->load->library('validation');
    
    $fields['username'] = 'User Name';
    $fields['passwd'] = 'Password';
    
    $this->validation->set_fields($fields);
    $this->validation->set_error_delimiters('<div class="error">', '</div>');
    
    $rules['username'] = 'trim|required|callback_check_login';
    $rules['passwd'] = 'trim|required|md5';
    
    $this->validation->set_rules($rules);
    
    if ($this->validation->run() == FALSE) {
        // Send user back
        $data['title'] = 'Temp Title';
        $this->load->view('loginview', $data);
           } else {
        // Process Login
        echo "You are logged in!";
        }
    }
function check_login($username)
{
   $this->validation->set_message('check_login', 'Your login information is invalid. Please try again.');
   // This function does not work without reapplying md5 to the passwd field
   $mdpassword = md5($this->validation->passwd);
   // Check to see if a user exists
   $this->db->where('userid', $username);
   $this->db->where('password', $mdpassword);
   $query = $this->db->get('users');
   if ($query->num_rows() > 0) { return TRUE; } else { return FALSE; }
}


Messages In This Thread
Question about callback function - by El Forum - 03-18-2008, 12:46 PM
Question about callback function - by El Forum - 03-20-2008, 01:37 AM
Question about callback function - by El Forum - 03-20-2008, 02:40 AM
Question about callback function - by El Forum - 03-20-2008, 05:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB