Skip to content

Instantly share code, notes, and snippets.

@maxfridbe
Created December 21, 2012 20:26
Show Gist options
  • Save maxfridbe/4355580 to your computer and use it in GitHub Desktop.
Save maxfridbe/4355580 to your computer and use it in GitHub Desktop.
domain authentication filter
#region Authentication
private List<string> getGroupNames(string userName)
{
using (var pc = new PrincipalContext(ContextType.Domain, _domainUri))
{
var identity = UserPrincipal.FindByIdentity(pc, userName);
if (identity == null)
return new List<string>();
var src = identity.GetGroups(pc);
var result = src.Select(sr => sr.SamAccountName).ToList();
//var result = new List<string>();
//src.ToList().ForEach(sr => result.Add(sr.SamAccountName));
return result;
}
}
private bool validateCred(string username, string password)
{
using (var context = new PrincipalContext(ContextType.Domain, _domainUri))
{
return context.ValidateCredentials(username, password);
}
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment