0
votes

I am trying to use the Auth module with ORM driver in Kohana 3.3.0, but the only thing I can do is insert new users in the database. I can't login with them.

                $user = ORM::factory('User')->create_user($user_data, array(
                'username',
                'password')
            );
            $user->save();
            $user_id = !empty($user->id) ? $user->id : 0;
            $user_type = !empty($_POST['admintype'] ? $_POST['admintype'] : 3);
            //$user->add('roles', ORM::factory('Role', array('name' => 'login')));
            $user->add('roles', $user_type);

user is created but when i try to login it returns null

            $user_name =  !empty($_POST['username']) ? $_POST['username'] : '';
        $userpassword = !empty($_POST['userpassword']) ? ($_POST['userpassword']) : '';           

        $user = Auth::instance()->login($user_name, $userpassword);
1
Please provide your code where you are getting this error so we can diagnose the problem. - RyanNerd
thanks code added in question body. @RyanNerd - Muhammad irfan
check the password is encrypted or not... - Sayed Mohd Ali
bbfcde02189e21be35c50a716744c7df8c64853a1fc1320b3e5abd2c9179eeff password in database - Muhammad irfan
What are the values of $user_name and $userpassword before this $user = Auth::instance()->login($user_name, $userpassword); is executed? Perhaps these data points are null or invalid?? - RyanNerd

1 Answers

1
votes

Auth->login() returns login status, so it should be:

$auth = Auth::instance();
if($auth->login($user_name, $userpassword)) {
  $user = $auth->get_user()
} else {
  throw HTTP_Exception::factory('403', 'Login fail');
}

And better use native kohana functions to get values form arrays:

$user_name =  Arr::get($_POST,'username','');

or in controller use:

$user_name =  $this->request->post('username','')