Files: Security: added message for brut force exception

This commit is contained in:
Maksim Chegulov 2023-04-28 16:24:58 +03:00
parent 804132eecc
commit 6a9bef4707
4 changed files with 17 additions and 5 deletions

View File

@ -905,6 +905,15 @@ namespace ASC.Files.Core.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to You have tried too many times to enter your password. Please try again later.
/// </summary>
public static string ErrorMessage_SharePasswordManyAttempts {
get {
return ResourceManager.GetString("ErrorMessage_SharePasswordManyAttempts", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You cannot edit archived rooms.
/// </summary>

View File

@ -481,4 +481,7 @@ Highest compatibility with docx, xlsx, pptx. </value>
<data name="DefaultExternalLinkTitle" xml:space="preserve">
<value>External link</value>
</data>
<data name="ErrorMessage_SharePasswordManyAttempts" xml:space="preserve">
<value>You have tried too many times to enter your password. Please try again later</value>
</data>
</root>

View File

@ -289,7 +289,7 @@ public class SecurityControllerCommon : ApiControllerBase
{
var ip = MessageSettings.GetIP(_httpContextAccessor.HttpContext?.Request);
_ = _bruteForceLoginManager.Increment(key, ip, true, out _);
_ = _bruteForceLoginManager.Increment(key, ip, true, out _, FilesCommonResource.ErrorMessage_SharePasswordManyAttempts);
var validationInfo = await _externalShare.ValidateAsync(key, inDto.Password);

View File

@ -43,7 +43,7 @@ public class BruteForceLoginManager
_distributedCache = distributedCache;
}
public bool Increment(string key, string requestIp, bool throwException, out bool showRecaptcha)
public bool Increment(string key, string requestIp, bool throwException, out bool showRecaptcha, string exceptionMessage = null)
{
showRecaptcha = true;
@ -53,7 +53,7 @@ public class BruteForceLoginManager
{
if (throwException)
{
throw new BruteForceCredentialException();
throw new BruteForceCredentialException(exceptionMessage);
}
return false;
@ -63,7 +63,7 @@ public class BruteForceLoginManager
{
if (GetFromCache<string>(blockCacheKey) != null)
{
throw new BruteForceCredentialException();
throw new BruteForceCredentialException(exceptionMessage);
}
var historyCacheKey = GetHistoryCacheKey(key, requestIp);
@ -85,7 +85,7 @@ public class BruteForceLoginManager
if (throwException)
{
throw new BruteForceCredentialException();
throw new BruteForceCredentialException(exceptionMessage);
}
return false;