【问题标题】:Authantication returning false Laravel 4身份验证返回错误的 Laravel 4
【发布时间】:2013-12-27 17:42:42
【问题描述】:

我正在用 laravel 编写一个简单的身份验证表单。
在尝试了两个不同的教程后,它仍然返回 false。
注册工作正常,但我的登录不是。
这是登录控制器:

        public function getLogin() {
            $this->layout->content = View::make('user.login');
    }

    public function postSignin() {
            if (Auth::attempt(array('email'=>Input::get('email'), 'password'=>Input::get('password'))))
            {
                return Redirect::to('user/dashboard')->with('message', 'You are now logged in!');
            } 
            else 
            {
                return Redirect::to('user/login')
                    ->with('message', 'Your username/password combination was incorrect')
                    ->withInput();
            }
    }

    public function getDashboard() {
            $this->layout->content = View::make('user.dashboard');
    }

路线:

Route::controller('user', 'UserController');

和视图:

{{ Form::open(array('url'=>'user/signin', 'class'=>'form-signin')) }}
<h2 class="form-signin-heading">Please Login</h2>

{{ Form::text('username', null, array('class'=>'input-block-level', 'placeholder'=>'Username')) }}
{{ Form::password('password', array('class'=>'input-block-level', 'placeholder'=>'Password')) }}

{{ Form::submit('Login', array('class'=>'btn btn-large btn-primary btn-block'))}}
{{ Form::close() }}

【问题讨论】:

    标签: php mysql authentication laravel


    【解决方案1】:

    在您的表单中,您有 username 的输入,但在您的控制器中,您有 Input::get('email')

    你必须像那样编辑你的表单......

    {{ Form::text('email', null, array('class'=>'input-block-level', 'placeholder'=>'Username')) }}
    

    ...你的控制器像这样

    Auth::attempt(array('email'=>Input::get('username'), 'password'=>Input::get('password')))
    

    【讨论】:

      【解决方案2】:

      我发现我没有用

      设置密钥
      php artisan key:generate 
      

      我的密码字段只有 32 个字符而不是 60 个。
      终于搞定了!

      【讨论】:

        猜你喜欢
        • 2014-07-19
        • 2021-01-01
        • 1970-01-01
        • 2013-09-09
        • 1970-01-01
        • 2020-10-15
        • 2017-06-12
        • 1970-01-01
        • 2016-08-17
        相关资源
        最近更新 更多