如何重写Laravel 的attempt方法
1 回答
守着一只汪
TA贡献1872条经验 获得超3个赞
默认是使用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());
- 1 回答
- 0 关注
- 2333 浏览
添加回答
举报
0/150
提交
取消