[eluser]dadamssg[/eluser]
So im trying to validate a simple login form. I'm trying to check if the username and password were found in my database. I don't know how to grab the cleaned password into my username_check function though. How do i assign that?
my controller
Code:
<?php
class Login extends Controller {
function Login()
{
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
}
function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|callback_username_check|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('login_view');
}
else
{
$this->load->view('login_view');
}
function username_check($user, $pass)
{
$query = $this->db->query("SELECT loginName,active FROM Member WHERE loginName='$user'
AND password=md5('$pass')");
if($query->result()->num_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
}
?>
and my login_view
Code:
<?php
echo validation_errors();
echo form_open('login');
?>
<p><input type='text' name='username' /></p>
<p><input type='password' name='password' /></p>
<p><input type='submit' value='Submit' /></p>
</form>