mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: totp 2fa; httpcontext extension for jwtuser; asp.net data protection; prevent banned users from certain actions; account deletion requires 2fa if enabled; making users admins requires 2fa if enabled; httpcontext extension to get ip; enhance user store
refactor: organize dtos by domain; verification providers use verification context; move ip parsing into http context extensions chore: clean code
This commit is contained in:
@@ -2,34 +2,11 @@
|
||||
{
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user