33 lines
891 B
C#
33 lines
891 B
C#
|
namespace Galaeth.Core.Extensions;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Extension methods for strings.
|
||
|
/// </summary>
|
||
|
public static class StringExtensions
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Mask an email address for logging purposes.
|
||
|
/// </summary>
|
||
|
/// <param name="emailAddress">The email address to obfuscate.</param>
|
||
|
/// <returns>The obfuscated email address, or the original if there's an issue with the email address.</returns>
|
||
|
public static string MaskEmailAddress(this string emailAddress)
|
||
|
{
|
||
|
if (string.IsNullOrWhiteSpace(emailAddress))
|
||
|
{
|
||
|
return string.Empty;
|
||
|
}
|
||
|
|
||
|
if (!emailAddress.Contains('@'))
|
||
|
{
|
||
|
return emailAddress;
|
||
|
}
|
||
|
|
||
|
if (emailAddress.StartsWith('@'))
|
||
|
{
|
||
|
return emailAddress;
|
||
|
}
|
||
|
|
||
|
return $"{emailAddress[0]}****{emailAddress[(emailAddress.IndexOf('@') - 1) ..]}";
|
||
|
}
|
||
|
}
|