public override async Task <bool> UserIsActiveAsync(IsActiveContext context, string userId) { using (IDependencyResolver resolver = _dependencyManager.CreateChildDependencyResolver()) { IBitChangeSetManagerRepository <User> usersRepository = resolver.Resolve <IBitChangeSetManagerRepository <User> >(); Guid userIdAsGuid = Guid.Parse(userId); return(await(await usersRepository.GetAllAsync(CancellationToken.None)) .AnyAsync(u => u.Id == userIdAsGuid)); } }
public override async Task <string> GetUserIdByLocalAuthenticationContextAsync(LocalAuthenticationContext context) { string username = context.UserName; string password = context.Password; if (string.IsNullOrEmpty(username)) { throw new ArgumentException(nameof(username)); } if (string.IsNullOrEmpty(password)) { throw new ArgumentException(nameof(password)); } using (MD5 md5Hash = MD5.Create()) { byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(password)); StringBuilder sBuilder = new StringBuilder(); foreach (byte d in data) { sBuilder.Append(d.ToString("x2")); } password = sBuilder.ToString(); } username = username.ToLower(); User user = null; using (IDependencyResolver resolver = _dependencyManager.CreateChildDependencyResolver()) { IBitChangeSetManagerRepository <User> usersRepository = resolver.Resolve <IBitChangeSetManagerRepository <User> >(); user = await(await usersRepository.GetAllAsync(CancellationToken.None)) .SingleOrDefaultAsync(u => u.UserName.ToLower() == username && u.Password == password); } if (user == null) { throw new DomainLogicException("LoginFailed"); } return(user.Id.ToString()); }