using System; using System.Collections.Concurrent; using System.Threading; using System.Threading.Tasks; namespace EmbedIO.Authentication { /// /// Simple HTTP basic authentication module that stores credentials /// in a . /// public class BasicAuthenticationModule : BasicAuthenticationModuleBase { /// /// Initializes a new instance of the class. /// /// The base route. /// The authentication realm. /// /// If is or the empty string, /// the Realm property will be set equal to /// BaseRoute. /// public BasicAuthenticationModule(string baseRoute, string? realm = null) : base(baseRoute, realm) { } /// /// Gets a dictionary of valid user names and passwords. /// /// /// The accounts. /// public ConcurrentDictionary Accounts { get; } = new ConcurrentDictionary(StringComparer.InvariantCulture); /// protected override Task VerifyCredentialsAsync(string path, string userName, string password, CancellationToken cancellationToken) => Task.FromResult(VerifyCredentialsInternal(userName, password)); private bool VerifyCredentialsInternal(string userName, string password) => userName != null && Accounts.TryGetValue(userName, out var storedPassword) && string.Equals(password, storedPassword, StringComparison.Ordinal); } }