简体   繁体   English

Laravel 5.1用户登录不起作用

[英]Laravel 5.1 user login not working

I have a registration form which works to register and login user. 我有一个注册表格,可以注册和登录用户。 I use $this->middleware('auth'); 我使用$this->middleware('auth'); in the controllers on protected routes to prompt users to login. 在受保护路由上的控制器中以提示用户登录。 The login form passes a POST request to Laravel's AuthController w/ username and password: 登录表单通过用户名和密码将POST请求传递给Laravel的AuthController:

 <input type="hidden" name="_token" value="XXXXXXXXXX">
    <div class="widget-content">
        <input type="text" placeholder="Username" name="username">
        <input type="password" placeholder="Password" name="password">
        <input class="btn btn-blue pull-right" type="submit" />
    </div>
</form>

Routes: 路线:

//authentication routes
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

I've tried using the authentication system's off-the-shelf postLogin() functionality, tried passing username, name, email to it without any luck. 我尝试使用身份验证系统的现有postLogin()功能,尝试将用户名,名称和电子邮件传递给它,但没有任何运气。 I tried overriding the parent method like this: 我试图像这样重写父方法:

public function postLogin(Request $request)
{
    $username = $request->input('username');
    $password = $request->input('password');

    if (Auth::attempt(['name' => $username, 'password' => $password])) {
        // Authentication passed...
        return redirect('dashboard');
    } else {
        return redirect()->intended('auth/login');
    }
}

EDIT: 编辑:

(This is old, For anyone having this issue.) The correct use of the hash function is (这是旧的,对于有此问题的任何人。)正确使用哈希函数是

$password = Hash::make('yourPasswordString');

$result = Hash::check('yourPasswordString', $password);  //returns true

can this be the CSFR token? 这可以是CSFR令牌吗? Since you are not using a facade to call the form you may need to add in the token call just after opening the form tag. 由于您没有使用外观来调用表单,因此可能需要在打开form标签之后立即添加令牌调用。

Here is the call: 这里是电话:

{!! {!! csrf_field() !!} {!! csrf_field()!!} {!! Form::hidden('token', $token) !!} 形式:: hidden('token',$ token)!!}

如果您使用内置的登录功能,Laravel还会散列您的密码,因此,如果您要散列密码,请检查模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM