使用种子用户凭据,我无法使用以下代码登录我的网站:
public function doLogin(Request $request)
{
$user = User::whereUsername($request->username)->first();
if (Hash::check($request->password, $user->password)) {
Auth::login($user, true);
return redirect('/headquarters');
} else {
return redirect('/login');
}
}
昨晚工作得很好。从那时起,我已经刷新了迁移,这可能在某处引发了一些奇怪的事情。
好奇的路线:
use Illuminate\Support\Facades\Auth;
Route::group(['middleware' => ''], function() {
Route::get('/sandbox', 'SandboxController@index');
Route::get('/', ['uses' => 'IndexController@index']);
Route::get('/login', ['uses' => 'HomeController@showLogin']);
Route::post('/login', ['uses' => 'HomeController@doLogin']);
Route::get('/logout', ['uses' => 'HomeController@doLogout']);
我做错了什么?为了以防万一,我已经清除了路由和编写器缓存,并且可以从播种器中逐字复制并粘贴凭据但仍然失败。
在登录屏幕上打印数据会产生以下结果:
input password is: asdf
input username is: naltroc
$user is : App\Models\User Object
(
[fillable:protected] => Array
(
[0] => username
[1] => email
[2] => password
[3] => cash
[4] => has_fights_pending
[5] => active_character
[6] => created_at
[7] => updated_at
)
[hidden:protected] => Array
(
[0] => password
[1] => remember_token
)
[connection:protected] =>
[table:protected] =>
[primaryKey:protected] => id
[keyType:protected] => int
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[id] => 4
[username] => naltroc
[email] => t@mail.com
[password] => $2y$10$8s2luMe5zKglh0cKr0tdjeBdi5.Y6iClBKnVKJc5/bW
[has_fights_pending] => 0
[active_character] =>
[cash] => 42
[prestige] => 0
[notoriety] => 0
[remember_token] =>
[created_at] =>
[updated_at] =>
)
[original:protected] => Array
(
[id] => 4
[username] => naltroc
[email] => t@mail.com
[password] => $2y$10$8s2luMe5zKglh0cKr0tdjeBdi5.Y6iClBKnVKJc5/bW
[has_fights_pending] => 0
[active_character] =>
[cash] => 42
[prestige] => 0
[notoriety] => 0
[remember_token] =>
[created_at] =>
[updated_at] =>
)
答案 0 :(得分:0)
嘿,只需按照文档
https://laravel.com/docs/5.4/hashing
如果不能正常工作,请更新数据库中的密码&然后再试一次。
使用以下方法
设置密码Hash::make("NewPassword");//set the return text in DB
同时测试$request->password
dd($request->password);