gpt4 book ai didi

php - 在 laravel 中处理登录尝试次数太多?

转载 作者:行者123 更新时间:2023-12-05 07:29:22 27 4
gpt4 key购买 nike

用户已经超过了他们允许的最大登录尝试次数,这将通过用户名和客户端的 IP 地址来确定,我使用 trait AuthenticatesUsers 拉入。您查看上述特征的内部,您会看到另一个特征 ThrottlesLogins 被引入。

授权配置:

'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
'admin-web' => [
'driver' => 'session',
'provider' => 'admins',
],
'admin-api' => [
'driver' => 'passport',
'provider' => 'admins',
],
],

授权 Controller :

 class AuthController extends Controller
{

use ThrottlesLogins;

public function login(Request $request)
{
$method = __FUNCTION__;

//set validations
$validator = Validator::make($request->all(), [
'email' => 'required|string|email',
'password' => 'required|string|min:6',
]);
if ($validator->fails()) {
return (new FailedServerResponse($this->controller, $method, $this->errorType['validation'], $validator->errors()))->show();
}

$admin = Admin::where('email', $request->email)->first();

if ( $this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}

if (Auth::guard('admin-web')->attempt(['email' => $request->email, 'password' => $request->password, 'is_active' => 1], true)) {
try {
$token = $admin->createToken('register admin')->accessToken;
} catch (\Exception $e) {
return (new FailedServerResponse($this->controller, $method, $this->errorType['token']))->show();
}

return $token;
//success and everything is ok
$extra = ['token' => $token, 'is_register' => true];
return (new UserResponse($admin->load('userActivities', 'addresses.city.province', 'wallets', 'userGalleries'), $actionName, $extra))->withPrimaryLayout();

} else {
return (new FailedServerResponse($this->controller, $method, $this->errorType['notFound']))->show();
}
}

protected function hasTooManyLoginAttempts(Request $request)
{
$attempts = 2;
$lockoutMinites = 10;
return $this->limiter()->tooManyAttempts(
$this->throttleKey($request), $attempts, $lockoutMinites
);
}

hasTooManyLoginAttempts 无效。你能帮帮我吗?

最佳答案

也许问题在于

$this->incrementLoginAttempts($request);

如果登录尝试不成功,我们将增加登录尝试次数并将用户重定向回登录表单。

关于php - 在 laravel 中处理登录尝试次数太多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52831648/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com