User-1648726239 posted
I have a requirement where the users of my application will be authenticated against AD, but the user being dispersed across OU's inside Active Directory.
Assuming that all the users are present inside CN= USER can be authenticated using the below code and it worked for me
-------------------------------------------------------------------------
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry("LDAP://server/CN=Users;DC=mydomain;DC=in");
entry.Username = domainAndUsername;
entry.Password = pwd;
entry.AuthenticationType = AuthenticationTypes.Secure;
try
{
//Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
--------------------------------------------------------------------------
AS my application users are dispersed across AD and are found inside OU's within AD. i need a solution where i pull out all the
USERS inside the AD and authenticate against their credentials.
IDE : Visual Studio 2005
Thanks In Advance
PRUTHVI SAGAR HN