1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-16 07:07:32 -05:00

[PM-5518] Refactor Email Token Providers (#3784)

* new email token providers

* move email redaction to core helpers

* make token options configurable

* protected setters on options

* fix email token provider tests

* fix core tests

---------

Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
This commit is contained in:
Kyle Spearrin
2024-07-11 14:39:27 -04:00
committed by GitHub
parent 1292736f54
commit d2567dd42d
9 changed files with 131 additions and 78 deletions

View File

@ -876,4 +876,40 @@ public static class CoreHelpers
{
return _whiteSpaceRegex.Replace(input, newValue);
}
public static string RedactEmailAddress(string email)
{
if (string.IsNullOrWhiteSpace(email))
{
return null;
}
var emailParts = email.Split('@');
string shownPart;
if (emailParts[0].Length > 2 && emailParts[0].Length <= 4)
{
shownPart = emailParts[0].Substring(0, 1);
}
else if (emailParts[0].Length > 4)
{
shownPart = emailParts[0].Substring(0, 2);
}
else
{
shownPart = string.Empty;
}
string redactedPart;
if (emailParts[0].Length > 4)
{
redactedPart = new string('*', emailParts[0].Length - 2);
}
else
{
redactedPart = new string('*', emailParts[0].Length - shownPart.Length);
}
return $"{shownPart}{redactedPart}@{emailParts[1]}";
}
}