using System; using System.Collections.Generic; using System.Threading.Tasks; namespace AS400API.Auth; public sealed class DemoUserStore { private readonly Dictionary _users; public DemoUserStore() { _users = new Dictionary(StringComparer.OrdinalIgnoreCase) { ["admin"] = CreateUser("admin", "Pass@123", new[] { Roles.Admin, Roles.Operator }), ["operator"] = CreateUser("operator", "Pass@123", new[] { Roles.Operator }) }; } public ValueTask FindByNameAsync(string username) { _users.TryGetValue(username, out var user); return ValueTask.FromResult(user); } public bool ValidateCredentials(DemoUser user, string password) => PasswordHasher.Verify(password, user.PasswordHash, user.PasswordSalt); private static DemoUser CreateUser(string username, string password, IReadOnlyCollection roles) { var (hash, salt) = PasswordHasher.HashPassword(password); return new DemoUser(username, hash, salt, roles); } }