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:
@ -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]}";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user