Created
December 21, 2012 20:26
-
-
Save maxfridbe/4355580 to your computer and use it in GitHub Desktop.
domain authentication filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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