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

[eluser]zimco[/eluser]
I'm trying to create the most basic login area for my application: one admin user and password stored in a mysql table.

I tried following the tutorial by Alex Biddle that uses Erkanaauth but i've mucked it all up and can't get it to work.

Can someone tell me what i am doing wrong and how to fix it?

File locations:
application/libraries/Erkanaauth.php
application/helpers/erkanaauth_helper.php
application/controllers/admin/authcontroller.php
application/controllers/admin/login.php
application/views/admin/content-login.php

The mysql table was created with the following command:
CREATE TABLE `users` (
`id` smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
`username` varchar(10) NOT NULL,
`password` varchar(10) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
);

The admin user was inserted into the database with
INSERT INTO users (username, password) VALUES ("admin", sha1("demo"));

Here's the code for my login.php controller:

Code:
<?php

class Login extends Controller
{

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


/*======================================================================*\
    Function:    index()
    Purpose:    Provide the Login entry page.
    Input:        
    Output:        Display login page view
\*======================================================================*/
    function index()
    {
        $login_form_rules = array
        (
            'username' => 'callback_check_username',
            'password' => 'required'
        );
        $login_form_fields = array
        (
            'username' => 'username',
            'password' => 'password'
        );

        $this->validation->set_fields($login_form_fields);
        $this->validation->set_rules($login_form_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-login', $data);
          // set the footer view
          $data['footer'] = $this->load->view('footer', '');
        }
        else
        {
            redirect('admin/success');
        }

    }


/*======================================================================*\
    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
\*======================================================================*/
}

?>

Here's the code for my login view, content-login.php:

Code:
<div id="content">

<div id="loginform">
<h1>Login</h1>
&lt;?php echo $this->validation->error_string; ?&gt;

&lt;?php $attributes = array('id' => 'login'); ?&gt;
&lt;?php echo form_open('admin/index', $attributes); ?&gt;

  <p>
  <label for="username">Username: </label>
  &lt;?php
  $username = array(
              'username'    => 'username',
              'maxlength'   => '10',
              'size'        => '25',
            );
  echo form_input($username);
  ?&gt;
  <p>
  <label for="password">Password: </label>
  &lt;?php
  $password = array(
              'password'    => 'password',
              'maxlength'   => '10',
              'size'        => '25',
            );
  echo form_input($password);
  ?&gt;
  </p>
  <p>
    &lt;?php echo form_submit('submit', 'Submit'); ?&gt;
  </p>  
  
  &lt;?php echo form_close(); ?&gt;
  
</div>

</div>


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