I have to change the 'users' table to a different table name as per our organization standard. It has different column name for password. So my users table will be 'User' and password column name will be 'encryptedPassword' to match the org standards.
I do not have any migration that refers to users
table. Instead, I use User
table as a base table for login/registration etc.
Please note that I am using following User Provider :
/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php
I am using Laravel5.4 and want to use default LoginController and RegisterController. So I made following changes to ensure that my code still works with the new user table and password column name.
(1) For registering user:
(1.1) Http/Controllers/Auth/RegisterController.php
- In the create() method changed the 'password' to 'encryptedPassword' to reflect the modified column name for password. (please note I am not making any changes to blade template for Login UI)
$user = User::create([ 'name' => $data['name'], 'email' => $data['email'], 'encryptedPassword' => bcrypt($data['password']) ]);
(1.2) User.php ( Eloquent Model for user registration and login functionality) - Added following variable to indicate custom table name for User and custom password column
protected $table = 'User'; protected $primaryKey = 'userId'; protected $encryptedPassword = 'encryptedPassword'; protected $fillable = [ 'name', 'email', 'encryptedPassword', ]; protected $hidden = [ 'encryptedPassword', 'remember_token', ];
Also added a method to return correct password column
public function getAuthPassword() { return $this->encryptedPassword; }
After this Registering the User is NOT working in laravel 5.4
The error message is :
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'homestead.users' doesn't exis
( I am using homestead
as my DB name)
(2) Login User functionality.
But this is not yet working with the following changes I thought I am supposed to do.
(2.1) Http/Controllers/Auth/LoginController.php
Added following :
protected $encryptedPassword = 'encryptedPassword';
public function credentials(Request $request)
{ return $request->only($this->username(), $this->password());
}
Added this one also:
protected function password() { return $this->encryptedPassword; }
But Login is not working as expected.
On login screen I see the error message under Email-Address that
'These credentials do not match our records.'
What am I missing?