Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:28:41+00:00 2026-06-18T04:28:41+00:00

I am using codeigniter framework. I have a login model and a controller with

  • 0

I am using codeigniter framework. I have a login model and a controller with a view. I have admin as username and admin as password set in the users table in my db for test purpose.
But when ever I use admin13356 or admindsgsd or adminWHATEVER with admin as password, the login is successful. I dont understand why.

My controller function is as follows.

function check(){
        $this->load->model('loginModel');
        $query = $this->loginModel->validate();
        if($query){
            $data = array('username' => $this->input->post('username'),
                           'is_logged_in' => true
                        );
            $this->session->set_userdata($data);
            //redirecting to appropriate page 
            redirect('success');
        }else{
            $this->session->set_flashdata('loginCheck','Username/Password Comination Incorrect!');
            redirect('login');
        }
    }

And my model is as below.

function validate(){
            $this->db->where('username', $this->input->post('username'));
            $this->db->where('password', md5($this->input->post('password')));
            $query = $this->db->get('users');
            if($query->num_rows() == 1){
                return true;
            }

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:28:42+00:00Added an answer on June 18, 2026 at 4:28 am

    What version of PHP are you running? I’ve had problems with PHP before where it returns TRUE for non returns.

    Try adding return false to your validate() method:

    function validate(){
        $this->db->where('username', $this->input->post('username'));
        $this->db->where('password', md5($this->input->post('password')));
        $query = $this->db->get('users');
        if($query->num_rows() == 1){
            return true;
        }
    
        return false;
    }
    

    Also, Model’s should be input agnostic. Definitely think about moving the $this->input->post() to the controller and pass the values in as parameters:

    This allows you to use the validate() method in other scenarios. For example (re-validating the password when the username isn’t supplied via post but via session).

    Controller

    function check(){
        $this->load->model('loginModel');
        $query = $this->loginModel->validate($this->input->post('username'), $this->input->post('password'));
        if($query){
            $data = array(
               'username' => $this->input->post('username'),
               'is_logged_in' => true
            );
            $this->session->set_userdata($data);
            //redirecting to appropriate page 
            redirect('success');
        }else{
            $this->session->set_flashdata('loginCheck', 'Username/Password Combination Incorrect!');
            redirect('login');
        }
    }
    

    Model

    function validate($username, $password){
        $this->db->where('username', $username);
        $this->db->where('password', md5($password));
        $query = $this->db->get('users');
        if($query->num_rows() == 1){
            return true;
        }
    
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Codeigniter framework to create my web application. I have a login form
I'm using Codeigniter framework to create my web application. I have a login form
Both zend and CI framework have seperate Model, View, Controller directories. My doubt is
I am using native PHP sessions ($_SESSION) with CodeIgniter framework. I have a Login
I am using Codeigniter framework and I have a form with input fields. When
I am using codeigniter framework for my site and I have done two site
I'm using CodeIgniter (a PHP framework) to build an app, and I have an
Im using jquerymobile together with codeigniter framework and I'm having a problem I have
I am using codeigniter framework. where should i sanitize PHP input - controller or
I'm creating my own script using the CodeIgniter MVC framework. Now, i want users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.