Laravel overrides EloquentUserProvider to change password field name in validateCredentials ()

I managed to change the password field in the code by overriding the various classes / methods. But I'm trying to override EloquentUserProvider and the validateCredentials () method, I get an error -

ErrorException in AuthUserProvider.php line 15:
Argument 1 passed to App\Providers\AuthUserProvider::__construct() must be an instance of App\Helpers\Sha1Hasher, instance of Illuminate\Foundation\Application given

I created an override of App \ Providers \ AuthUserProvider.php -

namespace App\Providers;

use Illuminate\Contracts\Auth\Authenticatable as UserContract;
use App\Helpers\Sha1Hasher as HasherContract;
use Illuminate\Auth\EloquentUserProvider;

class AuthUserProvider extends EloquentUserProvider
{
/**
 * AuthUserProvider constructor.
 * @param HasherContract $hasher
 * @param string $model
 */
public function __construct(HasherContract $hasher, $model)
{
    parent::__construct($hasher, $model);
}

/**
 * Validate a user against the given credentials.
 *
 * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
 * @param  array  $credentials
 * @return bool
 */
public function validateCredentials(UserContract $user, array $credentials)
{
    // $plain = $credentials['sha_pass_hash'];
    // return HasherContract::check(...);;
}
}

using Laravel 5.2.22.

+4
source share
1 answer

How did you "redefine" an instance EloquentUserProvider? Because Laravel creates an instance Authbased on what you installed auth.driver.

Illuminate/Auth/CreatesUserProviders@createUserProvider, EloquentUserProvider. bind Illuminate\Auth\EloquentUserProvider.

, , , __construct . , , :

new AuthUserProvider($app);

:

return new EloquentUserProvider($this->app['hash'], $config['model']);

, AuthManager. . Illuminate\Auth\AuthManager@provider line + - 266.

!! :

auth()->provider(AuthUserProvider::class);
+2

All Articles