Welcome Guest, Not a member yet? Register   Sign In
Login Validation
#2

[eluser]James Gifford[/eluser]
There are any number of ways to do validation that depend a lot on your preferred coding style. Here is a simple way:
Code:
function login ()
{
   $this->load->library('validation');

   $fields['user_name'] = 'username';
   $fields['password'] = 'password';

   $this->validation->set_fields($fields);

   $rules['user_name'] = 'required|callback__check_login';
   $rules['password'] = 'required';

   $this->validation->set_rules($rules);

   if ($this->validation->run())
   {
      // Log user in
   }

   // Display the login form
}

function _check_login ($user_name)
{
   $this->validation->set_message('_check_login', 'Your login information is invalid');

   $this->db->where('user_name', $user_name);
   $this->db->where('password', $this->validation->password);
   $query = $this->db->get('users');

   return ($query->num_rows() > 0);
}


Messages In This Thread
Login Validation - by El Forum - 03-06-2008, 02:04 PM
Login Validation - by El Forum - 03-06-2008, 04:02 PM
Login Validation - by El Forum - 03-06-2008, 04:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB