Click here to Skip to main content
15,901,035 members
Home / Discussions / C#
   

C#

 
QuestionC# & LDAP Pin
AnhTin13-Apr-06 0:34
AnhTin13-Apr-06 0:34 
QuestionPhone number Pin
mehrdadc4813-Apr-06 0:30
mehrdadc4813-Apr-06 0:30 
AnswerRe: Phone number Pin
snouto13-Apr-06 0:58
snouto13-Apr-06 0:58 
QuestionDetecting sound volume with c# using .NET Pin
coverblew13-Apr-06 0:12
coverblew13-Apr-06 0:12 
AnswerRe: Detecting sound volume with c# using .NET Pin
coverblew13-Apr-06 4:39
coverblew13-Apr-06 4:39 
GeneralRe: Detecting sound volume with c# using .NET Pin
mav.northwind13-Apr-06 22:19
mav.northwind13-Apr-06 22:19 
QuestionAccess global focused control Pin
dct_flare13-Apr-06 0:04
dct_flare13-Apr-06 0:04 
QuestionGet Group in LDAP Pin
AnhTin12-Apr-06 23:43
AnhTin12-Apr-06 23:43 
I have code Authenticated user by LDAP
i have GetGroups() method but it has _filterAttribute but i dont know it "_filterAttribute"

Some body help me !!


private String _path;
private String _filterAttribute;

public Form1(String path)
{
_path = "LDAP://cctvs1/CN=Users,DC=TESTLDAP,DC=com";
}

public bool IsAuthenticated(String domain, String username, String pwd)
{
String domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry("LDAP://cctvs1/CN=Users,DC=TESTLDAP,DC=com", domainAndUsername, pwd);

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;
}

//Update the new path to the user in the directory.
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}

return true;
}

public String GetGroups()
{
DirectorySearcher search = new DirectorySearcher("LDAP://cctvs1/CN=Users,DC=TESTLDAP,DC=com");
search.Filter = "(cn=" + _filterAttribute + ")";
search.PropertiesToLoad.Add("memberOf");
StringBuilder groupNames = new StringBuilder();

try
{
SearchResult result = search.FindOne();

int propertyCount = result.Properties["memberOf"].Count;

String dn;
int equalsIndex, commaIndex;

for(int propertyCounter = 0; propertyCounter < propertyCount; propertyCounter++)
{
dn = (String)result.Properties["memberOf"][propertyCounter];

equalsIndex = dn.IndexOf("=", 1);
commaIndex = dn.IndexOf(",", 1);
if(-1 == equalsIndex)
{
return null;
}

groupNames.Append(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1));
groupNames.Append("|");

}
}
catch(Exception ex)
{
throw new Exception("Error obtaining group names. " + ex.Message);
}
return groupNames.ToString();
}
}
QuestionPost back where to inset the code Pin
papa198012-Apr-06 22:41
papa198012-Apr-06 22:41 
AnswerRe: Post back where to inset the code Pin
Dinuj Nath13-Apr-06 0:37
Dinuj Nath13-Apr-06 0:37 
GeneralRe: Post back where to inset the code Pin
papa198013-Apr-06 3:48
papa198013-Apr-06 3:48 
GeneralRe: Post back where to inset the code Pin
Dinuj Nath13-Apr-06 5:37
Dinuj Nath13-Apr-06 5:37 
QuestionAdding a row in a database Pin
alee15.10.8812-Apr-06 21:47
alee15.10.8812-Apr-06 21:47 
AnswerRe: Adding a row in a database Pin
J4amieC12-Apr-06 21:49
J4amieC12-Apr-06 21:49 
GeneralRe: Adding a row in a database Pin
alee15.10.8812-Apr-06 22:01
alee15.10.8812-Apr-06 22:01 
GeneralRe: Adding a row in a database Pin
J4amieC12-Apr-06 22:36
J4amieC12-Apr-06 22:36 
GeneralRe: Adding a row in a database Pin
albCode12-Apr-06 23:47
albCode12-Apr-06 23:47 
GeneralRe: Adding a row in a database Pin
J4amieC13-Apr-06 0:14
J4amieC13-Apr-06 0:14 
AnswerRe: Adding a row in a database Pin
Guffa13-Apr-06 1:31
Guffa13-Apr-06 1:31 
GeneralRe: Adding a row in a database Pin
J4amieC13-Apr-06 1:45
J4amieC13-Apr-06 1:45 
AnswerRe: Adding a row in a database Pin
Guffa12-Apr-06 21:51
Guffa12-Apr-06 21:51 
QuestionThread Synchronization program Pin
eric_tran12-Apr-06 21:31
eric_tran12-Apr-06 21:31 
AnswerRe: Thread Synchronization program Pin
J4amieC12-Apr-06 21:47
J4amieC12-Apr-06 21:47 
GeneralRe: Thread Synchronization program Pin
eric_tran12-Apr-06 21:53
eric_tran12-Apr-06 21:53 
QuestionRandom number Pin
eric_tran12-Apr-06 21:13
eric_tran12-Apr-06 21:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.