How to do same as PrincipalContext.ValidateCredentials but with LdapConnection (non AD-specific)

Go To StackoverFlow.com

0

If I have a PrincipalContext connected to an ActiveDirectory server (with some credentials) then I can call its ValidateCredentials method to validate some other credentials (e.g. some other username/password pair that differs from the credentials used for the PrinicapContext's connection).

I want to do basically the same thing, but with an LdapConnection. I have an LdapConnection successfully connected and bound to an openLDAP server. Now I want to validate a different set of credentials. I expect these credentials will need to be a distinguished-name & password pair instead of a username & password pair as above; that's fine.

I suppose I could create a temporary second LdapConnection and validate by binding with the second set of credentials.

Is there a better way to do this? Particularly, is there a way to use my existing LdapConnection to validate/authenticate other credentials? Btw, I'm in C# 4.0 for this.

2012-04-04 21:40
by Tyler Laing


0

Application code can validate credentials by changing the authentication state of an existing connection (LDAPv3 only). This process is accomplished by transmitting a bind request and examining the response from the server. If the result code in the bind response from the server is 0, the the credentials are correct and the account (which is identified by the distinguished name) is usable. If the result code in the bind response is non-zero, then an error has occurred: Perhaps the credentials are not valid, the distinguished name does not exist, the account associated with the distinguished name is disabled, or some other error.

This can be done with an existing connection, or the application can establish a new connection and transmit the bind request on the new connection.

2012-04-05 09:52
by Terry Gardner
Thanks, I am using LDAPv3. I'm wanting to validate the second set of credentials without changing the authentication state of my existing connection. I'm not running into any issues with bad credentials. If I were to bind with the second credentials on the existing connection that would change my authentication state. In the PrincipalContext example, the second credentials can be validated with the existing connection without changing the authentication state of the connection. Is a bind request the only way to validate credentials? If so, then I'll create a second connection - Tyler Laing 2012-04-05 16:59
Yes, use the bind request to validate credentials - Terry Gardner 2012-04-05 20:52
Ads