feat: implement Turnstile verification for enhanced security during login and registration

refactor: remove unnecessary interfaces for services; change user key from UID to UUID
This commit is contained in:
2025-12-31 12:11:09 -05:00
parent 08c4be4f7e
commit 848b8598e5
27 changed files with 579 additions and 84 deletions
+23
View File
@@ -2,11 +2,34 @@
{
public class Utilities
{
public readonly static string[] ipHeaders =
[
"X-Forwarded-For",
"X-Real-IP",
"CF-Connecting-IP",
"True-Client-IP",
"X-Cluster-Client-IP",
"X-ProxyUser-IP"
];
public static string GenerateRandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var random = new Random();
return new string([.. Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)])]);
}
public static string GetRequestIP(HttpContext request)
{
foreach (var header in ipHeaders)
{
if (request.Request.Headers.TryGetValue(header, out Microsoft.Extensions.Primitives.StringValues value))
{
var ip = value.FirstOrDefault();
if (!string.IsNullOrEmpty(ip))
return ip.Split(',')[0].Trim();
}
}
return request.Connection.RemoteIpAddress?.ToString() ?? "Unknown";
}
}
}