public UserEntity Authenticate(string userName, string password) { var adHelper = new ActiveDirectoryHelper(_domainName, _adminUserName, _adminPassword); var user = adHelper.FindUser(userName); if (user == null) { return(null); } var validated = adHelper.Validate(user.UserPrincipalName, password); if (!validated) { return(null); } return(new UserEntity { Email = user.Email, Name = user.Name, Surname = user.Surname, UserPrincipalName = user.UserPrincipalName, AdLogonName = GetAdLogonName(user) }); }