User authentication LDAP C# 3.5

Hello,

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.

Thanks
Alonso
i9796674Asked:
Who is Participating?
 
angus_young_acdcConnect With a Mentor Commented:
Here is a link for many different AD methods.  
http://www.codeproject.com/KB/system/everythingInAD.aspx
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;
            search.PropertiesToLoad.Add("memberOf");
            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

0
 
i9796674Author Commented:
Hi,

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?

Thanks
Alonso
0
 
angus_young_acdcCommented:
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.  
0
 
bvRocksConnect With a Mentor Commented:
http://www.skilldrive.com/book/DOTNETinSamples.htm

You have a whole list of samples here
0
All Courses

From novice to tech pro — start learning today.