Welcome Guest, Not a member yet? Register   Sign In
Using Form_validation to check if username exists AND if password matches
#2

[eluser]pickupman[/eluser]
Form validation is too make sure form fields are to be filled in the way you want them to, and to assist in repopulating the fields. I agree callback could work a little better. The easier way to do this is to check if required fields are filled out. In form->validation->run() routine pass username and password to auth library like:
Code:
if($this->form_validation->run() && $this->auth->login($user, $pass)){
    redirect('user'); //Login successful
}else{
   $this->login(); //Load login page again
}

//IN auth->login
function login($user = FALSE, $pass = FALSE){
  if($user == FALSE || $pass == FALSE) return FALSE; //We need both credentials

  $query = $this->db_common->get_where('users', array('username' => $user, 'password' => md5($pass), 1 );
  if($query->num_rows() > 0)
     return $query->row(); //Return user credentials

  return FALSE; //Sorry user wasn't found
    
}

You could add set_flashdata(), and return a message to the user why login faild.


Messages In This Thread
Using Form_validation to check if username exists AND if password matches - by El Forum - 07-14-2010, 07:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB