Skip to content

Instantly share code, notes, and snippets.

@dalexsoto
Created February 4, 2012 19:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalexsoto/1739634 to your computer and use it in GitHub Desktop.
Save dalexsoto/1739634 to your computer and use it in GitHub Desktop.
Active Directory Account Manager
using System.DirectoryServices.AccountManagement;
......
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, ADDomain))
{
var user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, ADDomain + "\\" + username);
var group = GroupPrincipal.FindByIdentity(pc, "Admins. del dominio");
var y = user.IsMemberOf(group);
var z = user.GetGroups().ToList();
// validate the credentials
return pc.ValidateCredentials(username, password);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment