Php How can I customize the password field in Laravel HTTP Basic Authentication?

Php How can I customize the password field in Laravel HTTP Basic Authentication?,php,laravel,laravel-5.8,laravel-authentication,Php,Laravel,Laravel 5.8,Laravel Authentication,I want to change the password field to user_password in the SQL request when I use the connection HTTP Basic Authentication. The middleware that I use is auth.basic specific to Laravel. I managed to change the username by creating middleware, but I can't change the password field. class CustomBasicAuth extends AuthenticateWithBasicAuth { public function handle($request, Closure $next, $guard = null, $field = null) { $this->auth->guard($guard)->basic($field ?: 'user_user

I want to change the

password
field to
user_password
in the SQL request when I use the connection HTTP Basic Authentication. The middleware that I use is
auth.basic
specific to Laravel. I managed to change the username by creating middleware, but I can't change the password field.

class CustomBasicAuth extends AuthenticateWithBasicAuth
{
    public function handle($request, Closure $next, $guard = null, $field = null)
    {
        $this->auth->guard($guard)->basic($field ?: 'user_username');

        return $next($request);
    }
}

I did some research, and I saw that we have to try and modify this method.

/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php

class SessionGuard implements StatefulGuard, SupportsBasicAuth
{
    use GuardHelpers, Macroable;

    protected function basicCredentials(Request $request, $field)
    {
        return [$field => $request->getUser(), 'password' => $request->getPassword()];
    }
}

Does anyone know how to change it without modifying the base file?


#1

You can customize external package classes just by extending them and overriding the methods you need to be changed. It may require extending multiple classes in order to change the places where the base class is called to your custom one.


#2

You can customize external package classes just by extending them and overriding the methods you need to be changed. It may require extending multiple classes in order to change the base class calls to your custom one.

#3

Thanks, you helped me solve it.

#4

Ok, will post it as an answer then in case anyone else faces the same problem :)

#5

more precisely I created an SessionGuardExtended class that extends SessionGuard then I added in AppServiceProvider