0

我正在创建一个新用户,然后尝试让他们登录,用户被保存在数据库中,他们的角色也被保存。虽然我从来没有点击重定向说他们已经登录。我已经调试了 Auth::Instance->login 并且我回来了FALSE

public function action_index()
{

    $view = View::factory('index/home');

    if( Request::current()->post() ):
        $post = $_POST;

        try {
            $user = ORM::factory('User');

            $user->username = $post['username'];
            $user->password = $post["password"];
            $user->email = $post["email"];
            $user->logins = +1;
            $user->save();


            if ($user->saved() ):
                $user->add('roles', ORM::factory('Role')->where('name', '=', 'login')->find());


                $logged_in = Auth::instance()->login($post['username'], $post['password']); 

                echo Debug::vars($logged_in); exit;                 

                if ($logged_in):
                    HTTP::redirect("/dashboard/");  
                endif;

            endif;  

        } catch (Exception $e) {
            echo Debug::vars($e); exit;
        }
    endif;

    $index_page = $view->render();  
    $this->response->body($index_page);         
}

配置

return array(

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

);

哈希时密码可能有问题吗?

4

1 回答 1

0

您将密码以明文形式存储在数据库中(除非您应用某种过滤器)。尝试以下操作:

$user->password = Auth::instance()->hash($post["password"]);

这将确保密码在存储之前经过哈希处理。Auth在将密码与数据库中的值进行比较之前,将对密码进行哈希处理。

于 2013-12-12T15:00:39.307 回答