Welcome Guest, Not a member yet? Register   Sign In
Authentication Help
#1

[eluser]codeign00b[/eluser]
Hello everybody Smile
I'm looking for a help in authentication on my site. I have site where users must login to be able to access other part of the site. The problem is when I try to sign in I get the blank page. Sessions are stored in db but it seems like user is not recognized or something. If I write anything in e-mail and password field I get the same blank page.

Here is my code:

Controler (1):

Code:
<?php

class Reports extends CI_Controller {
    
    function index()
    {
        $is_logged_in = $this->session->userdata('is_logged_in');
          if (!isset($is_logged_in) || $is_logged_in != true)
        {
            $this->session->set_userdata('redirect_url', 'reports');
            redirect('signin');
            die();
        }
  
        //reports controller part

        //Load reports page
        $data['main_content'] = 'view_reports';
        $this->load->view('view_main', $data);
    }
}

Signin controller:
Code:
<?php

class Signin extends CI_Controller {

    function index()
    {
        //load libraries
        $this->load->library('form_validation');
                $this->load->library('session');
        //Form validation rules
        $this->form_validation->set_rules('useremail', 'E-mail', 'trim|required|valid_email|xss_clean');
        $this->form_validation->set_rules('userpassword', 'Password', 'trim|required|xss_clean');
                                    
        //Run Validation    
        if ($this->form_validation->run() == FALSE)
        {
            //page has not run or validation error
            $data['main_content'] = 'view_signin';
            $this->load->view('view_mainindex', $data);

        }
        else
        {    
            $this->load->model('model_signin');
            $query = $this->model_signin->validate();
            if($query) //If user's credentials validate
            {
            
                 $useremail = $this->input->post('useremail');    
                 $this->session->set_userdata('is_logged_in','true');
                 $this->session->set_userdata('useremail', $this->input->post('useremail'));
                 redirect('reports');    
                        
            }
            else
            {    
                 $data['errors'] = '<p>The email address or password you entered is incorrect.</p>';
             $data['main_content'] = 'view_signin';
             $this->load->view('view_mainindex', $data);
            
                }
            }
    }
    function is_logged_in()
    {
        $is_logged_in = $this->session->userdata('is_logged_in');
        
        if (!isset($is_logged_in) || $is_logged_in != true)
        {
            redirect('signin');
            die();
        }
    }
    
    
}

Signin model:
Code:
&lt;?php

class Model_signin extends Model{
    
    function validate()
    {    
        $this->load->helper('date');
        $this->load->helper('url');
        $this->load->library('encrypt');
        $salt = $this->config->item('salt');
        $this->db->where('useremail', $this->input->post('useremail'));
        $password = $this->input->post('userpassword');
        $sha1_password = $this->encrypt->sha1($salt.$password);
        $this->db->where('userpassword', $sha1_password);
        $query = $this->db->get('user');

        if($query->num_rows == 1)
        {    
            //get userid and add it to session data
            $this->db->where('useremail', $this->input->post('useremail'));
            $password = $this->input->post('userpassword');
            $sha1_password = $this->encrypt->sha1($salt.$password);
            $this->db->where('userpassword', $sha1_password);
            $userid = $this->db->get('user')->row()->userid;

            //add timestamp to last loggedin field in user table
            $data = array(
                      'last_login' => now(),
            'last_ip' => $this->input->ip_address()    
                         );
            $this->db->where('userid', $userid);
            $this->db->update('user', $data);
            
            //set userid into session
            $this->session->set_userdata('userid',$userid);
            return true;
            
        }
        else
        {
            return false;
        }
    }

config.php:

Code:
$config['sess_cookie_name']        = 'somesite';
$config['sess_expiration']        = 0;
$config['sess_timeout'] = 7200;
$config['sess_encrypt_cookie']    = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_storage'] = 'database';
$config['sess_database'] = 'default';
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']     = 300;
$config['sess_http_only'] = TRUE;
$config['sess_secure'] = TRUE;

What is wrong with this?


Messages In This Thread
Authentication Help - by El Forum - 04-11-2011, 06:33 AM
Authentication Help - by El Forum - 04-11-2011, 06:45 AM
Authentication Help - by El Forum - 04-11-2011, 06:48 AM
Authentication Help - by El Forum - 04-11-2011, 07:20 AM
Authentication Help - by El Forum - 04-11-2011, 07:21 AM
Authentication Help - by El Forum - 04-11-2011, 09:19 AM
Authentication Help - by El Forum - 04-12-2011, 02:08 AM
Authentication Help - by El Forum - 04-12-2011, 02:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB