Laravel要重写Router.php里面的`auth`方法,应该在什么地方重写
2个回答
展开全部
默认是使用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());
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());
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询