20 lines
954 B
C#
20 lines
954 B
C#
namespace NTP.Application.Auth;
|
|
|
|
/// <summary>
|
|
/// The user name typed on the sign-in page. Users type just their login; the legacy "DOMAIN.login" spelling (for example ASEZA.50034)
|
|
/// is still accepted, in which case the domain is taken from it instead of being looked up.
|
|
/// </summary>
|
|
public static class LoginName
|
|
{
|
|
/// <summary>
|
|
/// <c>Domain</c> is null when only a login was typed. <c>Login</c> is lower case and trimmed. A name with exactly two dot-separated
|
|
/// parts is "DOMAIN.login"; anything else is one login (no login in NTPUSERS contains a dot).
|
|
/// </summary>
|
|
public static (string? Domain, string Login) Parse(string userName)
|
|
{
|
|
var text = (userName ?? string.Empty).Trim();
|
|
var parts = text.Split('.', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
|
return parts.Length == 2 ? (parts[0], parts[1].ToLowerInvariant()) : (null, text.ToLowerInvariant());
|
|
}
|
|
}
|