dongyongkui6329 2018-06-16 16:17
浏览 36

如何自定义laravel登录以添加通用密钥?

how to overwrite laravel's login method, I want to add a universal key, to be able to enter the accounts of system users.

After making the login attempt and if it does not match the credentials of the database, make another attempt with a universal password that is in the code.

I think it is here (EloquentUserProvider) where the validation of credentials is done, but I do not know how to customize it so that it works as I wish.

public function validateCredentials(UserContract $user, array $credentials)
{
    $plain = $credentials['password'];

    return $this->hasher->check($plain, $user->getAuthPassword());
}

I´m usising laravel 5.6

  • 写回答

1条回答 默认 最新

  • douji1999 2018-06-16 16:37
    关注

    Laravel Fired sendFailedLoginResponse method after failed login. You can overwrite it.

    Check AuthenticatesUsers trait in LoginController

    protected function sendFailedLoginResponse(Request $request)
    {
       if($this->limiter()->attempts($this->throttleKey($request)) == 1){ //if first login attempt failed
          //implement your own login logic here with universal password 
    
       }else{
          throw ValidationException::withMessages([
            $this->username() => [trans('auth.failed')],
          ]);
       }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭