失败的次数和限制时间增加到配置文件里面
This commit is contained in:
@@ -26,6 +26,8 @@ namespace IRaCIS.Application.Services
|
||||
private readonly IMemoryCache _cache;
|
||||
|
||||
private readonly IOptionsMonitor<ServiceVerifyConfigOption> _verifyConfig;
|
||||
|
||||
|
||||
public UserService(IRepository<User> userRepository,
|
||||
|
||||
IMailVerificationService mailVerificationService,
|
||||
@@ -617,8 +619,8 @@ namespace IRaCIS.Application.Services
|
||||
{
|
||||
|
||||
const string cachePrefix = "login-failures:";
|
||||
const int maxFailures = 3;
|
||||
const int lockoutMinutes = 1;
|
||||
int maxFailures = _verifyConfig.CurrentValue.LoginMaxFailCount;
|
||||
int lockoutMinutes = _verifyConfig.CurrentValue.LoginFailLockMinutes;
|
||||
|
||||
// 生成缓存键
|
||||
string cacheKey = $"{cachePrefix}{userName}";
|
||||
@@ -637,7 +639,7 @@ namespace IRaCIS.Application.Services
|
||||
|
||||
if (failCount >= maxFailures)
|
||||
{
|
||||
throw new BusinessValidationFailedException($"密码连续错误3次,当前账号已被限制登录,请等待 {lockoutMinutes} 分钟后再试。");
|
||||
throw new BusinessValidationFailedException($"密码连续错误{maxFailures}次,当前账号已被限制登录,请等待 {lockoutMinutes} 分钟后再试。");
|
||||
}
|
||||
|
||||
var userLoginReturnModel = new LoginReturnDTO();
|
||||
|
||||
Reference in New Issue
Block a user