【发布时间】:2018-03-26 12:35:39
【问题描述】:
我想更改 Laravel 5.6 中的默认身份验证字段名称,它看起来适用于用户名但不适用于密码。
我查看了How to change / Custom password field name for Laravel 4 and Laravel 5 user authentication 这个问题,Sample data to test 有效,但不在我的登录表单中。
用户名为useUsername
密码是usePassword
在我的登录表单上,我测试了一些数据
当我尝试使用 db 中密码哈希的用户登录时,我得到These credentials do not match our records。
当我在数据库中使用没有密码哈希的用户登录时,我在vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php-> validateCredentials(UserContract $user, array $credentials) 中遇到问题Undefined index: password
我在loginController.php中更改的内容
protected function validateLogin(Request $request)
{
$this->validate($request, [
$this->username() => 'required',
'usePassword' => 'required',
]);
}
public function username()
{
return 'useUsername';
}
protected function credentials(Request $request)
{
return $request->only($this->username(), 'usePassword');
}
在Users.php
protected $table = 't_user';
public function getAuthPassword()
{
return $this->usePassword;
}
我希望你能帮助我解决这个问题,我真的不明白为什么我会得到这些不同的哈希或非哈希错误以及如何解决它。
MYT。
【问题讨论】:
标签: php laravel authentication laravel-5.6