Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: How can I change the default Auth Password field name?

Tags:

I am currently working on my first laravel project and I am facing a problem.

If you have experience with laravel you probably know that by calling php artisan make:auth you will get a predefined mechanism that handles login and registration.

This mechanism is set to understand a couple of commonly used words in order to automate the whole procedure.

The problem that occurs in my case is that I am using oracle db and it won't let me have a table column with the name of password because its a system keyword and it throws errors when trying to insert a user.

So far, I have tried to change my password column to passwd and it worked in my registration form as expected. The User row was successfully inserted and my page was redirected to /home.

Register

Success

But when I try to logout and then relogin, I get this error telling me that my credentials are not correct:

enter image description here

As for my code, I have changed my RegisterController.php so that it takes username instead of email

protected function validator(array $data) {     return Validator::make($data, [         'username' => 'required|max:50|unique:ECON_USERS',         'passwd' => 'required|min:6|confirmed',     ]); }  protected function create(array $data) {     return User::create([         'username'   => $data['username'],         'passwd'     => bcrypt($data['passwd'])     ]); } 

The User $fillable

protected $fillable = [     'username', 'passwd' ]; 

I am guessing that Auth is trying to authenticate with email and not username or that Auth is searching for password and not passwd.

like image 364
D.Intziadis Avatar asked Sep 07 '16 15:09

D.Intziadis


People also ask

How do I change my auth login URL in Laravel?

Override with: Route::get('/admin/login', 'Auth\AuthController@showLoginForm'); Route::post('/admin/login', 'Auth\AuthController@login'); Route::get('/admin/logout', 'Auth\AuthController@logout'); Note: Route::auth() automatically handles login, logout and register.

How do I change my Auth login?

How to Setup Laravel Login Authentication in Simple and Easy Steps. Run your php artisan make:auth and php artisan migrate in a new Laravel application. Later you have to navigate to your browser to http://your-app.test/register or any other URL that's alloted to your application.


1 Answers

For having username instead of email, you can overwrite username() in your LoginController.php

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

And for passwd instead of password, you can do define an accessor in your App\User.php

/**  * Get the password for the user.  *  * @return string  */ public function getAuthPassword() {     return $this->passwd; } 

login.blade.php : Replace email input with username but do not change the name of the input for password.

like image 151
Gaurav Avatar answered Sep 17 '22 09:09

Gaurav