Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below details (sample) given by customer. With the given details I would like to confirm that I could successfully connect with the LDAP with the given credentials. How to ensure that?

Please note that we are using C#.NET as development language. Thanks in advance.



DEV LDAP:
------------------
UserName: MyUser
Password: Sensitive

Bind Account:
------------------------
uid=MyUser,ou=Application,ou=Infrastructure,dc=MyDomain,dc=com
Posted
Updated 4-Oct-12 21:57pm
v2
Comments
Zoltán Zörgő 5-Oct-12 2:54am    
Not clear: if your code is working, than connection is successful. Isn't it?
PS: it is urgent for you, not for us, please don't urge.

You can try similar to this if you want to create an LDAP connection. This worked for me in my app.
C#
LdapConnection ldapConn = new LdapConnection(string.Format("{0}:{1}", "Your Server Name", "3268"));

ldapConn.SessionOptions.PingLimit = 500;

ldapConn.Credential = new NetworkCredential(username, password, domain);
ldapConn.AuthType = AuthType.Negotiate;
ldapConn.SessionOptions.Sealing = true;
ldapConn.SessionOptions.Signing = true;
ldapConn.Timeout = TimeSpan.FromHours(2);

try
{
  ldapConn.Bind();

}
catch (LdapException ldapEx)
{
   //exception handling
}


Or if you want to validate only the credentials you can try this
C#
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
   if (!context.ValidateCredentials(userName, password, ContextOptions.ServerBind))
   {
       // put your logic here.
   }
}


If the solution worked for you, please vote :)
 
Share this answer
 
If you have access to that LDAP server, you can test it with an existing tool, like LdapAdmin[^]. But if you don't have access, you have to believe, or it is not your concern, it is theirs, to give you proper credentials.
 
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