hi,
In my project i have to authenticate users from multiple domain.We are providing provision for entering these values from the screen username,password and domain.And i will use the following functions for validating the user
private
string GetActiveDirectoryPath(string strDomain)
{
string strLDAPQuery;
DirectoryEntry entryRoot = new DirectoryEntry("LDAP://RootDSE");
strLDAPQuery =
"LDAP://" + entryRoot.Properties["defaultNamingContext"][0].ToString();
int firstDCindex = strLDAPQuery.IndexOf("DC=");
int firstCommaIndex = strLDAPQuery.IndexOf(",");
strLDAPQuery = strLDAPQuery.Substring(0, firstDCindex + 3) + strDomain + strLDAPQuery.Substring(firstCommaIndex);
return strLDAPQuery;
}
public bool IsUserAuthicated(string userName,string Password)
{
bool autheticationResult=false;
try
{
DirectoryEntry deRootDSE;
string[] currentUserName = userName.Split('\\');
string activeDirectoryPath = GetActiveDirectoryPath(currentUserName[0]);
deRootDSE =
new DirectoryEntry(activeDirectoryPath, currentUserName[1], Password);
object nativeResult = deRootDSE.NativeObject;
autheticationResult=
true;
}
catch(Exception exception)
{
if(exception.Message.Contains("Logon failure: unknown user name or bad password."))
{
autheticationResult=
false;
}
}
return autheticationResult;
}
This works fine if we are validating the users in the same domain to which we are logged into the system.For other domain users its not working.Any help will be appreciated.