User authentication LDAP C# 3.5


Could please anyway send a sample code to
1. authenticate a user
2. check if the user is part of a group
3. Show attributes for that user, like name, surname, etc

I have tried different pieces of code I found on Google but nothing seems to work ok.

Who is Participating?
angus_young_acdcConnect With a Mentor Commented:
Here is a link for many different AD methods.
Also the following example may help you out, just set the properties to be the name, surname etc.

SortedList idList = new SortedList();
            DirectorySearcher search = new DirectorySearcher(domain);
            search.Filter = "(SAMAccountName=" + userName + ")";
            search.SearchScope = SearchScope.Subtree;
            int listIndex = 0;
            SearchResultCollection result = search.FindAll();           
            foreach (SearchResult res in result)
                foreach (ResultPropertyValueCollection arr in res.Properties.Values)
                    foreach (object obj in arr)
                        idList.Add(listIndex, myString);

Open in new window

i9796674Author Commented:

Thanks for the code but it does not seem to work.

I have changed the domain and userName but what should I do with myString? where is it defined?

I know the page you mention but I have not found an example that works well doing what I wanted to do. I thought to use LDAP on 3.5 it would be something link to the System.DirectoryServices.Protocols namespace... or am I wrong here?

Whoops!  Thats the problem with a fast copy/paste.  You can ignore the line  idList.Add(listIndex, myString); as that was just me building a specific string and passing it back in the list.  You can publish each object (in foreach (object obj in arr)) to whatever you want and it should give you the list of groups for a specific user.  
bvRocksConnect With a Mentor Commented:

You have a whole list of samples here
All Courses

From novice to tech pro — start learning today.