mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-18 15:42:26 +00:00
Remove broken and useless BlockDeniedUsers functionality
This commit is contained in:
parent
3e031a342f
commit
71a97894ad
5 changed files with 6 additions and 60 deletions
|
@ -79,22 +79,6 @@ public class LoginController : ControllerBase
|
||||||
|
|
||||||
if (ServerConfiguration.Instance.Authentication.UseExternalAuth)
|
if (ServerConfiguration.Instance.Authentication.UseExternalAuth)
|
||||||
{
|
{
|
||||||
if (ServerConfiguration.Instance.Authentication.BlockDeniedUsers)
|
|
||||||
{
|
|
||||||
string ipAddressAndName = $"{token.UserLocation}|{user.Username}";
|
|
||||||
if (DeniedAuthenticationHelper.RecentlyDenied(ipAddressAndName) || DeniedAuthenticationHelper.GetAttempts(ipAddressAndName) > 3)
|
|
||||||
{
|
|
||||||
this.database.AuthenticationAttempts.RemoveRange
|
|
||||||
(this.database.AuthenticationAttempts.Include(a => a.GameToken).Where(a => a.GameToken.UserId == user.UserId));
|
|
||||||
|
|
||||||
DeniedAuthenticationHelper.AddAttempt(ipAddressAndName);
|
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
|
||||||
Logger.LogWarn($"Too many recent denied logins from user {user.Username}, rejecting login", LogArea.Login);
|
|
||||||
return this.StatusCode(403, "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.database.UserApprovedIpAddresses.Where(a => a.UserId == user.UserId).Select(a => a.IpAddress).Contains(ipAddress))
|
if (this.database.UserApprovedIpAddresses.Where(a => a.UserId == user.UserId).Select(a => a.IpAddress).Contains(ipAddress))
|
||||||
{
|
{
|
||||||
token.Approved = true;
|
token.Approved = true;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
@ -54,8 +53,6 @@ public class AuthenticationController : ControllerBase
|
||||||
this.database.GameTokens.Remove(authAttempt.GameToken);
|
this.database.GameTokens.Remove(authAttempt.GameToken);
|
||||||
this.database.AuthenticationAttempts.Remove(authAttempt);
|
this.database.AuthenticationAttempts.Remove(authAttempt);
|
||||||
|
|
||||||
DeniedAuthenticationHelper.SetDeniedAt($"{authAttempt.IPAddress}|{user.Username}");
|
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
return this.Redirect("~/authentication");
|
return this.Redirect("~/authentication");
|
||||||
|
@ -76,8 +73,6 @@ public class AuthenticationController : ControllerBase
|
||||||
{
|
{
|
||||||
this.database.GameTokens.Remove(authAttempt.GameToken);
|
this.database.GameTokens.Remove(authAttempt.GameToken);
|
||||||
this.database.AuthenticationAttempts.Remove(authAttempt);
|
this.database.AuthenticationAttempts.Remove(authAttempt);
|
||||||
|
|
||||||
DeniedAuthenticationHelper.SetDeniedAt($"{authAttempt.IPAddress}|{user.Username}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
await this.database.SaveChangesAsync();
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
|
||||||
|
|
||||||
public static class DeniedAuthenticationHelper
|
|
||||||
{
|
|
||||||
public static readonly Dictionary<string, long> IPAddressAndNameDeniedAt = new();
|
|
||||||
public static readonly Dictionary<string, int> AttemptsByIPAddressAndName = new();
|
|
||||||
|
|
||||||
public static void SetDeniedAt(string ipAddressAndName, long timestamp = 0)
|
|
||||||
{
|
|
||||||
if (timestamp == 0) timestamp = TimestampHelper.Timestamp;
|
|
||||||
|
|
||||||
if (IPAddressAndNameDeniedAt.TryGetValue(ipAddressAndName, out long _)) IPAddressAndNameDeniedAt.Remove(ipAddressAndName);
|
|
||||||
IPAddressAndNameDeniedAt.Add(ipAddressAndName, timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool RecentlyDenied(string ipAddressAndName)
|
|
||||||
{
|
|
||||||
if (!IPAddressAndNameDeniedAt.TryGetValue(ipAddressAndName, out long timestamp)) return false;
|
|
||||||
|
|
||||||
return TimestampHelper.Timestamp < timestamp + 300;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddAttempt(string ipAddressAndName)
|
|
||||||
{
|
|
||||||
if (AttemptsByIPAddressAndName.TryGetValue(ipAddressAndName, out int attempts)) AttemptsByIPAddressAndName.Remove(ipAddressAndName);
|
|
||||||
AttemptsByIPAddressAndName.Add(ipAddressAndName, attempts + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int GetAttempts(string ipAddressAndName)
|
|
||||||
{
|
|
||||||
if (!AttemptsByIPAddressAndName.TryGetValue(ipAddressAndName, out int attempts)) return 0;
|
|
||||||
|
|
||||||
return attempts;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +1,12 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Settings.ConfigurationCategories;
|
namespace LBPUnion.ProjectLighthouse.Types.Settings.ConfigurationCategories;
|
||||||
|
|
||||||
public class AuthenticationConfiguration
|
public class AuthenticationConfiguration
|
||||||
{
|
{
|
||||||
public bool BlockDeniedUsers { get; set; } = true;
|
[Obsolete("Obsolete. This feature has been removed.", true)]
|
||||||
|
public bool BlockDeniedUsers { get; set; }
|
||||||
|
|
||||||
public bool RegistrationEnabled { get; set; } = true;
|
public bool RegistrationEnabled { get; set; } = true;
|
||||||
public bool UseExternalAuth { get; set; }
|
public bool UseExternalAuth { get; set; }
|
||||||
}
|
}
|
|
@ -22,7 +22,7 @@ public class ServerConfiguration
|
||||||
// You can use an ObsoleteAttribute instead. Make sure you set it to error, though.
|
// You can use an ObsoleteAttribute instead. Make sure you set it to error, though.
|
||||||
//
|
//
|
||||||
// Thanks for listening~
|
// Thanks for listening~
|
||||||
public const int CurrentConfigVersion = 2;
|
public const int CurrentConfigVersion = 3;
|
||||||
|
|
||||||
#region Meta
|
#region Meta
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue