[eluser]Unknown[/eluser]
I need to integrate my login validation with my form validation and database check--need some help with it:
The validation function from my controller:
Code:
function credentials()
{
$this->load->model('users_model');
$query = $this->users_model->validate();
if($query)
{
$data = array(
'email' => $this->input->post('email'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('dashboard');
}
else // incorrect username or password
{
$this->index();
}
}
My code for the model:
Code:
function validate()
{
$this->db->where('email', $this->input->post('email'));
$this->db->where('password', $this->input->post('password'));
$query = $this->db->get('users');
if($query->num_rows == 1)
{
return true;
}
}
Issue #1: my login form won't accept an email address that's not in the database (so the validation on the email is working), but the login form will accept any passwords or even a blank field! I don't have any security on the passwords right now (SHA2, etc.), as I'm just trying to get my arms around the basics (later I plan to use bcrypt). I've been testing out solutions for a couple of hours with no luck.
Issue #2: I have form validation fields that I would like to integrate with this function; I have the code for the form validation, but need help integrating it in with the functions above. Here's the code:
Code:
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'required|valid_email');
$this->form_validation->set_rules('password', 'password', 'required|min_length[8]');
$this->_email = $this->input->post('email');
$this->_password = $this->input->post('password');
if($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$this->load->view('hello');
}
Thanks in advance.