CodeIgniter Forums
help me for SimpleLoginSecure and my problem. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: help me for SimpleLoginSecure and my problem. (/showthread.php?tid=44089)



help me for SimpleLoginSecure and my problem. - El Forum - 08-02-2011

[eluser]SaSa[/eluser]
i use of library SimpleLoginSecure, don't know why after login output is 0, and set_userdata not have output and value not insert in database (ci_sessions->user_data) it is empty. validdata is rateun true but $this->session->userdata('logged_in') is false.
what is your comment? waht do i do?

this is my Controller:
Code:
function index()
    {
    if($this->session->userdata('logged_in')) {
        redirect('admin/tour_foreign/order_foreign_tour_insert');
    }else{
        //************** create captcha **************/    
        $vals = array(
        'img_path'     => './captcha/',
        'img_url'     => 'captcha/',
        );
        $cap = create_captcha($vals);
        $data['cap'] = $cap;
        $insert = array(
        'captcha_time'    => $cap['time'],
        'ip_address'    => $this->input->ip_address(),
        'word'     => $cap['word']
        );
        $query = $this->db->insert_string('captcha', $insert);
        $this->db->query($query);
        
        // First, delete old captchas
        $expiration = time()-7200; // Two hour limit
        $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);    
        
        // Then see if a captcha exists:
        $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
        $binds = array($this->input->post('captcha'), $this->input->ip_address(), $expiration);
        $query = $this->db->query($sql, $binds);
        $row = $query->row();
        
        if ($row->count == 0)
        {
        echo "0";
        }
        
        
        //************** check validation **************//
        $useradmin = $this->input->post('useradmin');
        $passadmin = $this->input->post('passadmin');
        $captcha = $this->input->post('captcha');
        $type = 'admin';
        if($this->simpleloginsecure->login($useradmin, $passadmin, $type)) {
        // success
        redirect('admin/tour_foreign/order_foreign_tour_insert');
        }    
        
        $this->load->view('admin/login', $data);
    }
    }
this is my change SimpleLoginSecure function login():
Code:
function login($user_email = '', $user_pass = '', $type = '')
    {
        $this->CI =& get_instance();

        if($user_email == ''){
            return false;
            $email_valid = '0';            
        }
        if($user_pass == ''){
            return false;
            $pass_valid = '0';
        }


        //Check if already logged in
        if($this->CI->session->userdata('user_email') == $user_email){
            return true;
            $email_valid = '1';
        }
        
        
        //Check against user table
        //$this->CI->db->where('user_email', $user_email);
        //$this->CI->db->or_where('type', $type);
        $query_type = $this->CI->db->get_where($this->user_table, array('type'=>$type));
        if ($query_type->num_rows() > 0){
            return true;
            $type_valid= '1';
        }else{
            return false;
            $type_valid= '0';
        }
        $query = $this->CI->db->get_where($this->user_table, array('user_email'=> $user_email));
        if ($query->num_rows() > 0)
        {
            $user_data = $query->row_array();

            $hasher = new PasswordHash(PHPASS_HASH_STRENGTH, PHPASS_HASH_PORTABLE);

            if(!$hasher->CheckPassword($user_pass, $user_data['user_pass'])){
                return false;
                $pass_valid = '0';
            }else{
                return true;
                $pass_valid = '1';
            }

            //Destroy old session
            $this->CI->session->sess_destroy();
            
            //Create a fresh, brand new session
            $this->CI->session->sess_create();

            $this->CI->db->where('user_id', $user_data['user_id']);
$this->CI->db->set('user_last_login', 'NOW()', FALSE);
$this->CI->db->update($this->user_table);

            //Set session data
            unset($user_data['user_pass']);
            $user_data['user'] = $user_data['user_email']; // for compatibility with Simplelogin
            $user_data['logged_in'] = true;
            $this->CI->session->set_userdata($user_data);

            return true;
        }
        else
        {
            return false;
        }    

    }

other Controller:
after validation is return true, output this code is '0'.
Code:
function order_foreign_tour_insert(){
        if($this->session->userdata('logged_in')) {
        $this->load->view('admin/foreign');
        }else{
        echo '0';
        }
    }
Explanation: Output if($this->session->userdata('logged_in')) in third code(function order_foreign_tour_insert()) is '0'. set_userdata not work and have problem. if Be true(Validation) value username and password and captcha, Output in third code is '0'(false). I hope you understand that help mefor solve the problem.



help me for SimpleLoginSecure and my problem. - El Forum - 08-02-2011

[eluser]SaSa[/eluser]
I hope you understand that help me for solve the problem.
please help me...


help me for SimpleLoginSecure and my problem. - El Forum - 08-03-2011

[eluser]SaSa[/eluser]
Not someone help?


help me for SimpleLoginSecure and my problem. - El Forum - 08-03-2011

[eluser]momo123[/eluser]
Well I'm too lazy to read all your code.
But as far I can see you misunderstand the "return" - statement.
If you write something like ...
Code:
if (..) {return true} else {return false}

you leave your function. The rest of your code will never be executed..

Hope that helps.
Mo