Welcome Guest, Not a member yet? Register   Sign In
(SOLVED)Need Login Help using Erkanaauth
#8

[eluser]zimco[/eluser]
I finally solved my login problems, but it was not easy. Besides the errors that people already pointed out as posted above there were errors that were not quite so obvious:
the copy of Erkanaauth that i had downloaded via the link posted in this forum thread was old and used getwhere(), which has been deprecated, so i had to replace all those calls to the new get_where, but the most irratating error was the fact that i created my table as posted above with:
Code:
`password` varchar(10) NOT NULL

Guess what happens when you SHA1 your password and insert it into the database? It's longer than 10 characters, but gets put into the database with just the first ten characters, so when you go to check for the dohash(password) it will never match (my-DUH moment)! Once i changed the password field to be long enough for a hashed password (`password` varchar(128) NOT NULL) it worked as expected.

Thanks for everybodies help and i've posted my finished working code below in hopes that it will help others learning to code a login box. FYI, i changed the name of my controller and view to sentry.php and content-sentry.php

I added an encryption key to my password by following Elliot Haughin's instructions and adding his _prep_password($password) function to the end of Erkanaauth which i will paste below too. Open-up your applications config.php file find and add a set of random numbers and letters at least 32 chararcters long:
Code:
$config['encryption_key'] = "";

Remember to change your users database password field to the password.encrypted value.

Here's the code for my login controller, named sentry.php

Code:
<?php

class Sentry extends Controller
{

    function Sentry()
    {
        parent::Controller();
        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css');
        $this->load->library('validation');
        $this->load->helper('form','security');
        $this->load->library('Erkanaauth');
    }


/*======================================================================*\
    Function:    index()
    Purpose:    Provide the Login entry page.
    Input:        
    Output:        Display login page view
\*======================================================================*/
    function index()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('validation');
        
//$rules['username'] = "trim|required|min_length[5]|max_length[10]|xss_clean";
$rules['username']    = "callback_check_username";
$rules['password'] = "trim|required";
        
        $this->validation->set_rules($rules);
                
        if ($this->validation->run() == FALSE)
        {
            //Load the view file
          $data['css'] = $this->css;
          $data['base'] = $this->base;
          // set the header view
          $data['header'] = $this->load->view('header', '');
          // set the page content
          $data['content'] = $this->load->view('admin/content-sentry', $data);
          // set the footer view
          $data['footer'] = $this->load->view('footer', '');
        }
        else
        {
            //Load the view file
          $data['css'] = $this->css;
          $data['base'] = $this->base;
          // set the header view
          $data['header'] = $this->load->view('header', '');
          // set the page content
          $data['content'] = $this->load->view('admin/content-success', $data);
          // set the footer view
          $data['footer'] = $this->load->view('footer', '');
        }

    }


/*======================================================================*\
    Function:    check_username($username)
    Purpose:    
    Input:        
    Output:        
\*======================================================================*/
    function check_username($username)
    {
        $this->load->helper('security');
        $password = dohash($this->input->post('password'));

        if ($this->erkanaauth->try_login(array('username' => $username, 'password' => $password)))
        {
            return TRUE;
        }
        else
        {
            $this->validation->set_message('check_username', 'Incorrect login info.');
            return FALSE;
        }
    }
    


/*======================================================================*\
                                  END
\*======================================================================*/
}

?>

oops too long of a post will add more later....


Messages In This Thread
(SOLVED)Need Login Help using Erkanaauth - by El Forum - 06-27-2008, 07:29 AM
(SOLVED)Need Login Help using Erkanaauth - by El Forum - 06-27-2008, 12:25 PM
(SOLVED)Need Login Help using Erkanaauth - by El Forum - 06-27-2008, 12:51 PM
(SOLVED)Need Login Help using Erkanaauth - by El Forum - 06-27-2008, 02:03 PM
(SOLVED)Need Login Help using Erkanaauth - by El Forum - 06-27-2008, 02:49 PM
(SOLVED)Need Login Help using Erkanaauth - by El Forum - 06-28-2008, 06:19 AM
(SOLVED)Need Login Help using Erkanaauth - by El Forum - 06-28-2008, 09:35 AM
(SOLVED)Need Login Help using Erkanaauth - by El Forum - 06-29-2008, 03:38 PM
(SOLVED)Need Login Help using Erkanaauth - by El Forum - 06-29-2008, 04:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB