Framework: Change default password column error.

Created on 6 Apr 2017  路  8Comments  路  Source: laravel/framework

  • Laravel Version: 5.4.17
  • PHP Version: 7.1.1
  • Database Driver & Version: MySQL 5.5.42

Description:

I am using Auth and trying to change the Password column which is by default "password".
Whenever I try to login it gives me an error from following file and line
EloquentUserProvider
I think it is define hardcoded a password column, i guess.

Can anyone look into please?

Steps To Reproduce:

N/A

Most helpful comment

@themsaid - he is saying that password is hardcoded as the name of the column on that line.

What happens if you are using a different column name to store the passwords?

All 8 comments

Yes there has to be a password column if you tend to use EloquentUserProvider

@themsaid - he is saying that password is hardcoded as the name of the column on that line.

What happens if you are using a different column name to store the passwords?

I would like to be able to override the password column name, as we can do with the username.

The password for the model is known via the Authenticatable Contract (getAuthPassword). The field in the credentials has to be password when passed to attempt so the provider knows which field it is going to do the hash check upon and which field to not search against with the query.

You can override the credentials and validateLogin to make this adjustment if needed. Example:

public function credentials(Request $request)
{
    return $request->only($this->username()) + ['password' => $request->input('your_form_field')];
}

I suppose a better question is why does anyone even need to change the column from the name password in the first place?

i.e. what is a use case that warrants a change to the framework to support it?

Someone may want the form field to be named something other than 'password' potentially.

There are no changes to the framework needed to be able to make the adjustments this issue speaks of.

Will be good if in next commits will be method to getting password field name like username:

Illuminate\Foundation\Auth\AuthenticatesUsers.php

  /**
     * Get the login username to be used by the controller.
     *
     * @return string
     */
    public function username()
    {
        return 'email';
    }
   public function password()
    {
        return 'password';
    }

@mcklayin with the fact a PR( #18723 ) to do just that was closed and the answer is usually to 'override' what you need, I dont see that happening ;-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments

digirew picture digirew  路  3Comments

klimentLambevski picture klimentLambevski  路  3Comments

kerbylav picture kerbylav  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments