如何重写Laravel 的attempt方法

如何重写Laravel 的attempt方法


慕姐4208626
浏览 2334回答 1
1回答

守着一只汪

默认是使用eloquent作为认证驱动器,所以看看Illuminate\Auth\EloquentUserProvider里面的实现public function validateCredentials(UserContract $user, array $credentials){$plain = $credentials['password'];return $this->hasher->check($plain, $user->getAuthPassword());}所以如果要改验证的逻辑,可以继承原有的驱动器,然后重写validateCredentials里面的逻辑class TestUserProvider extend EloquentUserProvider{public function validateCredentials(UserContract $user, array $credentials){$plain = $credentials['password'];return md5($plain) == $user->getAuthPassword();}}最后设置驱动器,建议加载AppServiceProvider的boot()里面Auth::setProvider(new TestUserProvider());
打开App,查看更多内容
随时随地看视频慕课网APP