[eluser]miwrath[/eluser]
Hey guys, this is my problem on my project about logging-in...
the problem is if i input 'correct' username & password...it can log in...nothings wrong...
BUT if i input my username & my password with a blank space...it can log in.
Now the thing is, I want this issue to solve...that users cannot log-in without using exact
data they have to input...i want to solve the spaces issue...
Please help me with this one...
I appreciate positive responses from all of the members...(:
this is my user_model code:
Code:
function User_model()
{
parent::Model();
}
function check_login($username, $password)
{
//login_checker
$query_str = "SELECT * FROM users WHERE username = ? and password = ?";
$result = $this->db->query($query_str, array($username, $password));
if ($result->num_rows() == 1)
{
return $result->row(0)->teach_id;
}
else
{
return false;
}
}
this is my controller codes:
Code:
function login()
{
$this->load->helper('security');
$this->form_validation->set_rules('username', 'Username', 'trim|required|max_length[30]|alpha_numeric|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|max_length[10]|alpha_numeric|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('view_registrar');
}
else
{
// echo 'You are great!';
//process the input and login the user;
$username = $_POST['username'];
$username = $this->input->post('username');
$password = $_POST['password'];
$password = $this->input->post('password');
//extract($_POST);
$teach_id = $this->User_model->check_login($username, $password);
if (! $teach_id)
{
//login failed error
$this->session->set_flashdata('login_error', TRUE);
redirect('index.php');
}
else
{
//login
$this->session->set_userdata(array(
'logged_in' => TRUE,
'teach_id' => $teach_id
));
redirect('index.php/registrar/main_page');
}