Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-01-2013, 06:24 PM   PM User | #1
JimBIRD85
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
JimBIRD85 is an unknown quantity at this point
Why Can't Registered Users Within My Membership Table Not Log Into My System?

Hi there i have several users created in my membership db table but since I added in my validateUsers function to my controller to make sure non registered users cannot sign into my site, registered users cannot log in either. Why is this?

Controller:

Code:
class Login extends CI_Controller
{
  function Login()
  {
parent::__construct();
$this->load->model('membership');
  }



  function loguserin()

  {

   $this->load->helper(array('form', 'url'));
  
   $this->load->library('form_validation');
  
   $this->form_validation->set_rules('username', 'Username', 'required|min_length[4]|max_length[12]|callback_validateUser|trim');
   $this->form_validation->set_rules('password', 'Password', 'required|md5|trim');


   $username = $this->input->post('username');
   $password = $this->input->post('password');



   if ($this->form_validation->run())
   {
   $this->validateUser($username, $password);
   $this->session->set_userdata('status', 'OK');
   $this->session->set_userdata('username', $username);

   redirect('home');
   }
   else
   {
   $this->session->set_userdata('status', 'NOT_OK');
   $this->load->view('shared/header');
   $this->load->view('account/logintitle');
   $this->load->view('account/loginview');
   $this->load->view('shared/footer');
   }
  }


   function validateUser($username, $password)
  {
      $this->db->select('*')->from('membership');
      $this->db->where('username', $username);
      $this->db->where('password',MD5($password));
      $query = $this->db->get();
    if ($query ->num_rows ==1)
   {
        return true;
   }
  
   else
   {
        var_dump($username, $password);// this only seems to throw back the username, not the password, don't know why
        $this->form_validation->set_message('validateUser', 'Invalid username/password');
        return false;
   }

}
  
   function index()
   {
        $this->load->view('shared/header');
        $this->load->view('account/logintitle');
        $this->load->view('account/loginview');
        $this->load->view('shared/footer');
  }
Thanks for the help
JimBIRD85 is offline   Reply With Quote
Old 01-01-2013, 07:22 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Does your password field in the database have enough characters to store the full MD5 version of the password? If it doesn't then it will be truncated (in the database) and will not match the password they are supplying.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 01-01-2013, 07:32 PM   PM User | #3
JimBIRD85
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
JimBIRD85 is an unknown quantity at this point
Hi thanks for the reply. I have decided to get rid of my md5 trait in my form validation as it was causing me issues like these. The issue has now been fixed
JimBIRD85 is offline   Reply With Quote
Reply

Bookmarks

Tags
codeigniter, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:08 AM.


Advertisement
Log in to turn off these ads.