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
Here is my way of changing the default email field of the Laravel login to 'email_address' without changing the vendor code.
I made a trait class that extends the vendor AuthenticatesUsers trait. And only extended the username method.
App\Http\Controllers\Auth\AuthenticatesLogins.php:
namespace App\Http\Controllers\Auth;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
trait AuthenticatesLogins
{
use AuthenticatesUsers {
AuthenticatesUsers::username as parentUsername;
}
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
$this->parentUsername();
return 'email_address';
}
}
Now in App\Http\Controllers\Controller\LoginController.php:
class LoginController extends Controller
{
use AuthenticatesLogins; // <-- for custom login fields
// etc.
And... done! Hope this helps.
There's a static solution for situations when implementing the given interface is not enough (e.g. you have two password columns, a user password and a support password).
$qry = DB::table('users')
->where('email', $email)
->whereNotNull('support_password')
->first();
if(!empty($qry))
{
$check = Hash::check($password, $qry->support_password);
if ($check)
{
Auth::loginUsingId($qry->id, true);
}
}
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')))
I have not tested this but I believe you just have to override a function in UserTrait.php although don't hack the source. In your models/User.php file add the following function.
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->user_password;
}