Question

I am trying to get the login to work in Kohana, but so far it fails to log the user in.

I have been successfully able to create new users, so I have all the tables set up.

My view for the login page is as follows,

<td style="vertical-align:top">
            <div id="log_in">
                <form class="pure-form pure-form-stacked" action="/kohana-blog/index.php/signup/login" method="post">
                    <fieldset>
                    <legend>Log In</legend>

                    <label for="username">Username</label>
                    <input id="username" name="username" type="text" placeholder="nonamedude" required>

                    <label for="password">Password</label>
                    <input id="password" name="password" type="password" placeholder="Password" required>

                    <label for="remember" class="pure-checkbox"></label>
                    <input id="remember" type="checkbox"> Remember me
                    <br>

                    <button type="submit" class="pure-button notice">Log In</button>
                    </fieldset>
                </form>
            </div>
        </td>

My controller is as follows

$this->template->content = View::factory('signup/home')
            ->bind('message', $message);

        if (HTTP_Request::POST == $this->request->method()) 
        {

            $remember = array_key_exists('remember', $this->request->post()) ? (bool) $this->request->post('remember') : FALSE;
            $remember = FALSE;
            $user = Auth::instance()->login($this->request->post('username'), $this->request->post('password'), $remember);
            if ($user) 
            {
                Request::current()->redirect('signup/home');
            } 
            else 
            {
                $message = "login failed";
            }
        }

I can't figure out why it doesn't authenticate the user. My auth.php is as follows:

'driver'       => 'orm',
    'hash_method'  => 'sha256',
    'hash_key'     => 'somerandomstring',
    'lifetime'     => 1209600,
    'session_type' => Session::$default,
    'session_key'  => 'auth_user',

Additionally, the roles_users table have the correct values and the users table has the data from the form.

Is there a way to debug this to find the source of the issue?

No correct solution

OTHER TIPS

First of all make sure your user has login role assigned in roles_users table.
By default you won't be able to login if you don't have this role.
Btw. it's cleaner to write:

$post = $this->request->post();
$user = Auth::instance()->login($post['email'], $post['password'], isset($post, 'remember'));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top