我已经设法通过覆盖各种类/方法来更改代码中的密码字段。但是在尝试覆盖 EloquentUserProvider 并且它是 validateCredentials() 方法后,我不断收到错误 -
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
我创建了一个覆盖应用程序''提供者''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(...);;
}
}
使用 Laravel 5.2.22。
你是如何"覆盖"EloquentUserProvider
的实例的?因为 Laravel 正在根据您设置auth.driver
创建Auth
实例。
检查它是否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
行 +- 266。
也许!! 未测试:
auth()->provider(AuthUserProvider::class);