Laravel:如何更改默认的“身份验证密码"字段名称
我目前正在做我的第一个laravel项目,但遇到了问题.
I'm currently working on my first laravel project and i'm facing a problem.
如果您有使用laravel的经验,您可能知道通过调用php artisan make:auth
您将获得处理登录和注册的预定义机制.
If you have experience with laravel you probably know that by calling php artisan make:auth
you will get a predefined mechanism that handles login and registration.
此机制设置为可以理解几个常用词,以使整个过程自动化.
This mechanism is set to understand a couple of commonly used words in order to automate the whole procedure.
在我的情况下出现的问题是我使用的是oracle db,它不会让我有一个名称为password
的表列,因为它是系统关键字,并且在尝试插入a时会引发错误.用户.
The problem that occurs in my case is that i'm using oracle db and it won't let me have a table column with the name of password
because its a system keyword and it throws errors when trying to insert a user.
到目前为止,我已经尝试将我的password
列更改为passwd
,并且它可以按预期在我的注册表中使用.用户行已成功插入,我的页面已重定向到/home.
So far, i've tried to change my password
column to passwd
and it worked in my registration form as expected. The User row was successfully inserted and my page was redirected to /home.
但是,当我尝试注销然后重新登录时,出现此错误,告诉我我的凭据不正确.
But when i try to logout and then relogin, i get this error telling me that my credentials are not correct.
对于我的代码,我已经更改了RegisterController.php
,以便它使用用户名而不是电子邮件
As for my code, i've changed my RegisterController.php
so that it takes username instead of email
protected function validator(array $data)
{
return Validator::make($data, [
'username' => 'required|max:50|unique:ECON_USERS',
'passwd' => 'required|min:6|confirmed',
]);
}
protected function create(array $data)
{
return User::create([
'username' => $data['username'],
'passwd' => bcrypt($data['passwd'])
]);
}
用户$ fillable
The User $fillable
protected $fillable = [
'username', 'passwd'
];
我猜测Auth尝试使用email
而不是username
进行身份验证,或者Auth搜索的是password
而不是passwd
I'm guessing that Auth is trying to authenticate with email
and not username
or that Auth is searching for password
and not passwd
For having username
instead of email
, you can overwrite username() in your LoginController.php
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
return 'username';
}
And for passwd
instead of password
, you can do define an accessor in your App\User.php
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->passwd;
}
login.blade.php :用username
替换email
输入,但不要更改password
的输入名称.
login.blade.php : Replace email
input with username
but do not change the name of the input for password
.