Welcome Guest, Not a member yet? Register   Sign In
Working Example for Erkana Auth
#1

[eluser]singlepringle[/eluser]
Hi, i just started with CI.

Currently i try to develop a secured backend with the Erkana Libary.
But i cant get it to work. Is anyone so kind to provide a simple working example including the views? I just don't get any further...

Thank you!
#2

[eluser]imzyos[/eluser]
paste your code!
#3

[eluser]singlepringle[/eluser]
Hi Imzyos,

thanks for the offer!
Problem: _check_login does not return any Value.

Controller login.php
Code:
class Login extends Controller {

    function Login()
    {
        parent::Controller();
        // load the associated language file
        $this->lang->load('layout');
        $this->lang->load('content');
        
        $this->load->library('Erkanaauth');
        $this->load->library('validation');
    }


    function index()
    {
        $rules['username'] = "required";
        $rules['password'] = "required";
        
        $this->validation->set_rules($rules);
        
        $username = $this->input->post('username');
        $password = $this->input->post('password');
    
      // Validation Rules and Fields
      if ($this->validation->run() == False) {
          $data['result'] ='no validation';
        $this->load->view('login', $data);

      } else {
          $this->_check_login($username, $password);
        if(!$this->erkanaauth->try_session_login($username, $password)) {
            $this->load->view('login');
        } else {
            $this->load->view('account');
        }
      }
    }
    
    function _check_login($username, $password) {
      $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_login', 'Incorrect login info.');
        return FALSE;

      }
    }
}
#4

[eluser]imzyos[/eluser]
you must call the function on validation check the user guide Callbacks: Your own Validation Functions
#5

[eluser]singlepringle[/eluser]
Ok, thanks i will do that.
#6

[eluser]Chris Newton[/eluser]
an example:

Code:
$rules['password']    =     'required|callback__check_password';
#7

[eluser]Chris Newton[/eluser]
a little more of the way I do it;

Code:
function _check_password($password) {
         $this->load->helper('erkanaauth');
        $this->load->library('encrypt');
          if ($this->erkanaauth->try_login(array('user_name'=>$this->input->post('username')))) {
            if ($password==$this->encrypt->decode(getField('password'))){
                return TRUE;
            } else {
            $this->validation->set_message('_check_password', 'Incorrect password');
            return FALSE;
              }
          } else {
               $this->validation->set_message('_check_password', '');
              return FALSE;
          }
    }




Theme © iAndrew 2016 - Forum software by © MyBB