laravel 4自定义命名密码列 [英] laravel 4 custom named password column
问题描述
所以我发现一些问题已经说,你必须覆盖getAuthPassword(),以从数据库提供自定义的密码列的名称。试图将此方法与数据库中的列具有相同的名称,但不工作。仍然会发生此错误:未定义的索引:密码。
这是auth:
code> if(Auth :: attempt(Input :: only('user_displayName'),Input :: get('user_password')))
尝试将form和controller中的user_password改为password无效。
所以问题是如果我有一个列一个数据库user_password是否有办法让Auth工作?
PS检查每个我找到的旧解决方案
EDIT
用户表的结构:
+ == ================== +
|用户|
+ ==================== +
| user_id |
+ ---------------------- +
| user_displayName |
+ ---------------------- +
| user_fname |
+ ---------------------- +
| user_lname |
+ ---------------------- +
| user_email |
+ ---------------------- +
| user_password |
+ ---------------------- +
| created_at |
+ ---------------------- +
| updates_at |
+ ---------------------- +
tldr;
但是,您无法通过不同的方式数组键到 Auth :: attempt
方法 - 只有密码
索引可以
首先,你做错了 - 你需要传递一个凭证数组作为第一个参数:
if(Auth :: attempt(Input :: only('user_displayName','user_password'))
接下来,不幸的是 Eloquent
提供程序在代码中硬编码了密码
数组索引,因此您不能将 user_password
传递给尝试
方法。
这是你需要的:
$ credentials = Input :: only('user_displayName');
$ credentials ['password'] = Input :: get('user_password');
if(Auth :: attempt($ credentials))
//或只是将表单中的输入重命名为password和:
if(Auth :: attempt(Input :: only('user_displayName','password')))
So I found a few problems already which says that you have to override getAuthPassword() to give custom name of password column from database. Tried putting this method with the same name as column in a database and didnt work. It still shoots this error: Undefined index: password.
This is the auth:
if (Auth::attempt(Input::only('user_displayName'), Input::get('user_password')))
Tried changing user_password to password both in form and controller nothing works.
So the question is if I have a column in a database called "user_password" is there a way to make Auth work?
P.S checked every older solution I found
EDIT
Structure of user table:
+======================+
| User |
+======================+
| user_id |
+----------------------+
| user_displayName |
+----------------------+
| user_fname |
+----------------------+
| user_lname |
+----------------------+
| user_email |
+----------------------+
| user_password |
+----------------------+
| created_at |
+----------------------+
| updated_at |
+----------------------+
tldr; You can name your password field anything you like, as long as your User model implements the interface correctly.
However you can't pass different array key to the Auth::attempt
method - only password
index can be there
First off you're doing it wrong - you need to pass an array of credentials as 1st param:
if (Auth::attempt(Input::only('user_displayName', 'user_password')))
Next, unfortunately Eloquent
provider has hard-coded password
array index in the code, so you can't pass user_password
to the attempt
method.
So this is what you need:
$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')))
这篇关于laravel 4自定义命名密码列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!