所以我已经发现了一些问题,这表明您必须重写 getAuthPassword() 才能从数据库中提供密码列的自定义名称。尝试将此方法与数据库中的列同名,但没有成功。它仍然会出现此错误:未定义索引:密码。
这是授权:
if (Auth::attempt(Input::only('user_displayName'), Input::get('user_password')))
尝试将表单和控制器中的 user_password 更改为密码,但没有任何效果。
所以问题是,如果我在数据库中有一个名为“user_password”的列,有没有办法让身份验证工作?
P.S 检查了我发现的每个旧解决方案
EDIT
用户表结构:
+======================+
| User |
+======================+
| user_id |
+----------------------+
| user_displayName |
+----------------------+
| user_fname |
+----------------------+
| user_lname |
+----------------------+
| user_email |
+----------------------+
| user_password |
+----------------------+
| created_at |
+----------------------+
| updated_at |
+----------------------+
太棒了;只要您的用户模型正确实现了接口,您就可以将密码字段命名为任何您喜欢的名称。
但是你不能将不同的数组键传递给Auth::attempt
仅方法password
索引可以在那里
首先,您做错了 - 您需要传递一组凭据作为第一个参数:
if (Auth::attempt(Input::only('user_displayName', 'user_password')))
接下来,不幸的是Eloquent
提供商已硬编码password
代码中的数组索引,所以不能通过user_password
to the attempt
method.
所以这就是你所需要的:
$credentials = Input::only('user_displayName');
$credentials['password'] = Input::get('user_password');
if (Auth::attempt($credentials))
// or simply rename the input in your form to password and:
if (Auth::attempt(Input::only('user_displayName', 'password')))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)