feat: add HideMiddleDigits
This commit is contained in:
parent
0d95262bb3
commit
dc078564ae
|
|
@ -23,7 +23,7 @@ public static class Utilities
|
||||||
|
|
||||||
var data = sha256.ComputeHash(Encoding.UTF8.GetBytes(text));
|
var data = sha256.ComputeHash(Encoding.UTF8.GetBytes(text));
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
foreach(var c in data)
|
foreach (var c in data)
|
||||||
{
|
{
|
||||||
sb.Append(c.ToString("x2"));
|
sb.Append(c.ToString("x2"));
|
||||||
}
|
}
|
||||||
|
|
@ -47,4 +47,36 @@ public static class Utilities
|
||||||
memcache.Compact(100);
|
memcache.Compact(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string HideMiddleDigits(string input, bool isEmail = false)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
|
{
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEmail)
|
||||||
|
{
|
||||||
|
int atIndex = input.IndexOf('@');
|
||||||
|
if (atIndex > 1)
|
||||||
|
{
|
||||||
|
string localPart = input.Substring(0, atIndex);
|
||||||
|
if (localPart.Length > 2)
|
||||||
|
{
|
||||||
|
string maskedLocalPart = $"{localPart[0]}{new string('*', localPart.Length - 2)}{localPart[^1]}";
|
||||||
|
return $"{maskedLocalPart}@{input.Substring(atIndex + 1)}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (input.Length > 6)
|
||||||
|
{
|
||||||
|
return $"{input.Substring(0, 3)}{new string('*', input.Length - 6)}{input.Substring(input.Length - 3)}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using BotSharp.Abstraction.Users.Enums;
|
using BotSharp.Abstraction.Users.Enums;
|
||||||
|
using BotSharp.Core.Infrastructures;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace BotSharp.OpenAPI.ViewModels.Users;
|
namespace BotSharp.OpenAPI.ViewModels.Users;
|
||||||
|
|
@ -57,8 +58,8 @@ public class UserViewModel
|
||||||
UserName = user.UserName,
|
UserName = user.UserName,
|
||||||
FirstName = user.FirstName,
|
FirstName = user.FirstName,
|
||||||
LastName = user.LastName,
|
LastName = user.LastName,
|
||||||
Email = user.Email,
|
Email = Utilities.HideMiddleDigits(user.Email, true),
|
||||||
Phone = !string.IsNullOrWhiteSpace(user.Phone) ? user.Phone.Replace("+86", String.Empty) : user.Phone,
|
Phone = Utilities.HideMiddleDigits((!string.IsNullOrWhiteSpace(user.Phone) ? user.Phone.Replace("+86", String.Empty) : user.Phone)),
|
||||||
Type = user.Type,
|
Type = user.Type,
|
||||||
Role = user.Role,
|
Role = user.Role,
|
||||||
Source = user.Source,
|
Source = user.Source,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue