0

I want to change the default auth fields name in Laravel 5.6, it looks like to work for the username but not for the password.
I looked this questions How to change / Custom password field name for Laravel 4 and Laravel 5 user authentication and the Sample data to test works but not in my login form.

username is useUsername
password is usePassword

On my login form, I tested to kind of data When I try to log with a user with the password hash in db, I get These credentials do not match our records.
When I log with a user without password hash in db, I get an issue Undefined index: password in the vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php-> validateCredentials(UserContract $user, array $credentials)

what I changed in the 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');
}

In Users.php

protected $table = 't_user';

public function getAuthPassword()
{
    return $this->usePassword;
}

I hope you could help me to solve this issue, I don't really understand why I get these different error with hash or not hash and how I could solve it.
MYT.

mytDRAGON
  • 59
  • 12

1 Answers1

0

I thing you can use a Hashing Password by Using Bcrypt in Laravel.

like

$password = Hash::make('yourpassword');

Basically, you'll do it when creating/registering a new user

then hash password will be store into database.

when you log in then you can remember your password otherwise it will give you error ...

if you forgot your hash password then you can bcrypt password by using this one

$password = bcrypt('admin');

I hope this will help you...

for more information of Hashing you can visit

Hashing in laravel

Jay Chauhan
  • 296
  • 3
  • 11
  • I doesn't solve my problem, as I write in the main post with my 2 exemples. If I try with the password hash, I get an error, and when I try with password non-hashed, the credentials are false – mytDRAGON Mar 28 '18 at 05:37
  • It solve the problem when I get the `Credentials not match` and now have the `Password not definided in ValidateCredentials()` which is normal when the 2 examples are swaped – mytDRAGON Mar 28 '18 at 05:44
  • i think hash password is secure to store a password in encypted format so that is normal... – Jay Chauhan Mar 28 '18 at 08:08
  • the problem is the `password not defined` not hash, anyway I solved my problem. By the way I don't use hash because I do some test, in future I'll use NTLMHash cause my user's data are from an AD – mytDRAGON Mar 28 '18 at 09:20