I have a registration form which works to register and login user. I use $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:
<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. 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? 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.
Here is the call:
{!! csrf_field() !!} {!! Form::hidden('token', $token) !!}
如果您使用内置的登录功能,Laravel还会散列您的密码,因此,如果您要散列密码,请检查模型。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.