Click here to Skip to main content
15,887,442 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I want to vb create code to connect to an LDAP and retrieve an specific user/password or specific user validation.

Im new, so any explained code example(s) would be very useful! Thanks!
Posted

1 solution

You can use the below function to fetch LDAP info:

C#
using System.Security.Principal;

private void GetUserName()
        {
            WindowsIdentity ident = WindowsIdentity.GetCurrent();
            WindowsPrincipal user = new WindowsPrincipal(ident);
            string username = StripDomainFromUserName(user.Identity.Name);

            using (DirectoryEntry de = new DirectoryEntry("LDAP://" + StripDomain(user.Identity.Name)))
            {
                using (DirectorySearcher adSearch = new DirectorySearcher(de))
                {
                    adSearch.Filter = "(sAMAccountName=" + username + ")";
                    SearchResult adSearchResult = adSearch.FindOne();

                    UserCredentials.CommitID = username;
                    UserCredentials.UserName = StripLoggedUserName(adSearchResult.Path);
                    UserCredentials.LoginUserName = StripLoggedUserName(adSearchResult.Path);
                    UserCredentials.LoginUserCommitID = username;
                }
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900