Jump to content

CodeIgniter login HELP PLEASE


dadamssg

Recommended Posts

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?

<?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;
                }
        
        }
    
    
}
}

?>

Link to comment
https://forums.phpfreaks.com/topic/187808-codeigniter-login-help-please/
Share on other sites

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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.