Author Topic: CodeIgniter login HELP PLEASE  (Read 874 times)

0 Members and 1 Guest are viewing this topic.

Offline dadamssgTopic starter

  • Devotee
  • Posts: 713
    • View Profile
CodeIgniter login HELP PLEASE
« on: January 09, 2010, 02:16:32 AM »
im trying to get a simple login to work with a callback function i created to make sure the password the person entered matches a username they entered in a form. right now if i leave the fields blank and push submit i get “Empty fields”, which is right. But if i enter something in both…i get “It WORKED.”...which it doesn’t work. The username and password im entering do not match so it should return FALSE. any help please?
Code: [Select]
<?php

class Login extends Controller {

    function 
Login()
    {
        
parent::Controller();
        
$this->load->database();
        
$this->load->library('session');
        
$this->load->helper(array('form''url'));
        
$this->load->library('form_validation');
    }

    function 
index()
    {
        
        
        
$this->form_validation->set_rules('username''Username''trim|required|xss_clean|callback_username_check');
        
$this->form_validation->set_rules('password''Password''trim|required|xss_clean|');
        
        
                if (
$this->form_validation->run() == FALSE)
                {
                    
$this->session->set_flashdata('message''Empty Fields.');
                    
redirect('mains');
                }
                else
                {
                    
                    
$this->session->set_flashdata('message''It WORKED.');
                    
redirect('mains');
                }
    
        
        function 
username_check()
        {
            
$user $this->input->post('username');
            
$pass $this->input->post('password');
            
$query $this->db->query("SELECT loginName,active FROM Member WHERE loginName='$user'
                                AND password=md5('
$pass')");
                if(
$query->num_rows() == 1)
                {
                return 
TRUE;
                }
                else
                {
                return 
FALSE;
                }
        
        }
    
    
}
}

?>

Offline didier8134

  • Irregular
  • Posts: 2
    • View Profile
Re: CodeIgniter login HELP PLEASE
« Reply #1 on: January 11, 2010, 08:54:12 AM »
Mmm, I don't know this framework, but I'm going to assume the problem here.

First of all, you should change the SQL to be something like: SELECT loginName FROM Member WHERE active AND (etc) - That is if the active is a bool field (1 or 0) in the db.

Secondly, you might want to change the code to this:  if($query->num_rows() === 1) Depending on what datatype the function returns...

Where and how is the username_check function called?

Offline dominicd

  • Irregular
  • Posts: 19
    • View Profile
Re: CodeIgniter login HELP PLEASE
« Reply #2 on: January 15, 2010, 06:54:03 AM »
because your returning it as true when input is put in regardless of the data entered.