1

我正在使用 Laravel 5.1 开发一个 webapp,我正在构建身份验证系统,我必须检查用户是否在六个月或更长时间内没有更改密码,我会使用中间件来检查,但我没有找到我怎么能正确地做到这一点。我创建了一个全局中间件,但它无法正常工作,因为我无法获得经过身份验证的用户。

我可能必须使用 AfterMiddleware 来检查密码吗?

4

2 回答 2

0

首先解释/说明您希望用户何时强制更改密码?身份验证时还是身份验证成功后?那我可以给你一个解决方案

于 2015-10-28T11:33:33.463 回答
0

那么你需要覆盖 AuthController 中的 postLogin 方法

公共函数 postLogin(请求 $request){

  $credentials  = ['email' => $request->email, 'password' => $request->password];

  if (Auth::attempt($credentials, $request->has('remember'))) {

      if((strtotime(Auth::user()->created_at) < strtotime('6 month ago'))){
        return redirect('your-reset-path);//redirect to password reset page
      }else{
        return redirect()->intended('/');
      }

  }

  return redirect($this->loginPath())
      ->withInput($request->only('email', 'remember'))
      ->withErrors([
          'email' => $this->getFailedLoginMessage(),
      ]);
  }

如果您想检查 created_at ,这将完成这项工作,但您宁愿使用另一个带有时间戳(last_password_updated)的字段,该字段仅在密码更改和首次创建时才会更新,它会更有效。

于 2015-10-28T12:25:25.417 回答