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.

1
  • I solved my problem by doing a custom AuthController. It was easiest for what I wanted to do. Commented Mar 28, 2018 at 9:11

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

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
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
i think hash password is secure to store a password in encypted format so that is normal...
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.