30 lines
763 B
C#
30 lines
763 B
C#
namespace UtopiaCanteenSystem.Services.Logging;
|
|
|
|
public static class LogMasking
|
|
{
|
|
public static string MaskCardId(string? cardId)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(cardId))
|
|
return "(empty)";
|
|
|
|
var s = cardId.Trim();
|
|
if (s.Length <= 4)
|
|
return new string('*', s.Length);
|
|
|
|
var visible = Math.Min(4, s.Length);
|
|
return s[..visible] + new string('*', s.Length - visible);
|
|
}
|
|
|
|
public static string MaskConnectionString(string? connectionString)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(connectionString))
|
|
return "(not configured)";
|
|
|
|
var s = connectionString.Trim();
|
|
if (s.Length <= 20)
|
|
return "***";
|
|
|
|
return s[..12] + "***" + s[^4..];
|
|
}
|
|
}
|