Skip to content

Lida dev #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/Infrastructure/BotSharp.Core/Infrastructures/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static string HashTextSha256(string text)

var data = sha256.ComputeHash(Encoding.UTF8.GetBytes(text));
var sb = new StringBuilder();
foreach(var c in data)
foreach (var c in data)
{
sb.Append(c.ToString("x2"));
}
Expand All @@ -47,4 +47,36 @@ public static void ClearCache()
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;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Core.Infrastructures;
using System.Text.Json.Serialization;

namespace BotSharp.OpenAPI.ViewModels.Users;
Expand Down Expand Up @@ -57,8 +58,8 @@ public static UserViewModel FromUser(User user)
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
Phone = !string.IsNullOrWhiteSpace(user.Phone) ? user.Phone.Replace("+86", String.Empty) : user.Phone,
Email = Utilities.HideMiddleDigits(user.Email, true),
Phone = Utilities.HideMiddleDigits((!string.IsNullOrWhiteSpace(user.Phone) ? user.Phone.Replace("+86", String.Empty) : user.Phone)),
Type = user.Type,
Role = user.Role,
Source = user.Source,
Expand Down