CodeIgniter Forums
CMS Login Help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: CMS Login Help (/thread-8485.html)



CMS Login Help - El Forum - 05-19-2008

[eluser]Drew Barontini[/eluser]
Alright, please go easy on me because of my newbie status with CI. I am creating a user login using just a name and password field. The username and password to login has been inserted manually into the database. I have created the controller, but I need some direction in creating the model to query the database, find out if the username and password are correct, and allow me to proceed to login to the admin_home view that I have yet to create, but we'll call it that for now.

Here is the controller thus far. It just has a success page if you satisfy the requirements, and the model I am trying to figure out how to create it.

Code:
<?php

class Login extends Controller {
    
    function index()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('validation');
        
        $rules['username']    = "trim|required|min_length[5]|max_length[12]|xss_clean";
        $rules['password']    = "trim|required|min_length[6]|md5";
        
        $this->validation->set_rules($rules);
        
        $fields['username'] = 'Username';
        $fields['password'] = 'Password';

        $this->validation->set_fields($fields);
                
        if ($this->validation->run() == FALSE)
        {
            $this->load->view('admin/login/login_view');
        }
        else
        {    
            $this->load->view('admin/login/login_success');    
        }
    }
}
?>

This may very well all be wrong. Will I create the model to query the database and check to see if the username and password match, and then replace the login_success view call in the else statement with a $this->load->model('admin/home/home_view');?

If anyone could help me out and give me some direction that would be tremendous. Also, are sessions a must even if it's just a login for myself on my own site? If so, where would I incorporate the sessions. If this is too much, just giving some general direction would be great. I should be able to figure it out. My issue is knowing where to put everything.

Thanks in advance and I apologize for the pathetic code Confusedhut:


CMS Login Help - El Forum - 05-20-2008

[eluser]Crimp[/eluser]
A login system for your CMS is an important security measure. It's hard to do one right unless you really know what you are doing. The good news is that several people have done one and posted the code in the Ignited Code section. Looking at the code of those systems will give you an idea of how it can be done. Some of your questions indicate that you should get a basic understanding of how these functions/systems work before attempting your own. To answer one of your questions: yes, a session is the preferred method of tracking the status of a user -- even if that user is you. You need to attach the status to the unique user so you can open and close doors to parts of your site.


CMS Login Help - El Forum - 05-20-2008

[eluser]Drew Barontini[/eluser]
Yeah, I was mainly just trying to get some direction. My code by no means is close to done and I wanted to see some login scripts that have been completed for something similar to what I'm trying to do. Thank you for the direction, and I'll look at some sample code people have completed.