PC Review


Reply
Thread Tools Rate Thread

Authenticate user in OpenLDAP with username and password

 
 
dorrit.Riemenschneider@communardo.de
Guest
Posts: n/a
 
      5th Jan 2007
I need to validate a user with username and password against our
OpenLDAP active directory. This is my code:

Private bool ValidateUser (string username, string password)
{
DirectoryEntry userEntry = new DirectoryEntry(
ldapPath, username, password,
AuthenticationTypes.Anonymous);
//Bind to the native AdsObject to force authentication.

Object obj = userEntry.NativeObject;
DirectorySearcher search = new
DirectorySearcher(userEntry);
search.Filter = "(cn=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (result != null)
return true;
else
return false;
}

The problem is, it returns also true if the username is correct, but
the password is false.
It looks like the user is located but not authenthicated.

I have already tried with several AuthenthicationTypes:
I get an exeption "invalid dn-syntax" for AuthenthicationTypes.None,
AuthenthicationTypes.Delegation, AuthenthicationTypes.FastBind,
AuthenthicationTypes.ReadOnlyServer, AuthenthicationTypes.Sealing.

I get an exception "Die angeforderte Authentifizierungsmethode wird
durch den Server nicht unterstützt" (authenthication method not
supported by server) for AuthenthicationTypes.Secure or if I don't
specify an AuthenthicationType.

Any help is appreciated!
Dorrit

 
Reply With Quote
 
 
 
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      5th Jan 2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
I need to validate a user with username and password against our
OpenLDAP active directory. This is my code:

Private bool ValidateUser (string username, string password)
{
DirectoryEntry userEntry = new DirectoryEntry(
ldapPath, username, password,
AuthenticationTypes.Anonymous);
//Bind to the native AdsObject to force authentication.

Object obj = userEntry.NativeObject;
DirectorySearcher search = new
DirectorySearcher(userEntry);
search.Filter = "(cn=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (result != null)
return true;
else
return false;
}

The problem is, it returns also true if the username is correct, but
the password is false.
It looks like the user is located but not authenthicated.

I have already tried with several AuthenthicationTypes:
I get an exeption "invalid dn-syntax" for AuthenthicationTypes.None,
AuthenthicationTypes.Delegation, AuthenthicationTypes.FastBind,
AuthenthicationTypes.ReadOnlyServer, AuthenthicationTypes.Sealing.

I get an exception "Die angeforderte Authentifizierungsmethode wird
durch den Server nicht unterstützt" (authenthication method not
supported by server) for AuthenthicationTypes.Secure or if I don't
specify an AuthenthicationType.

Any help is appreciated!
Dorrit





 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      5th Jan 2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
I need to validate a user with username and password against our
OpenLDAP active directory. This is my code:

Private bool ValidateUser (string username, string password)
{
DirectoryEntry userEntry = new DirectoryEntry(
ldapPath, username, password,
AuthenticationTypes.Anonymous);
//Bind to the native AdsObject to force authentication.

Object obj = userEntry.NativeObject;
DirectorySearcher search = new
DirectorySearcher(userEntry);
search.Filter = "(cn=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (result != null)
return true;
else
return false;
}

The problem is, it returns also true if the username is correct, but
the password is false.
It looks like the user is located but not authenthicated.

I have already tried with several AuthenthicationTypes:
I get an exeption "invalid dn-syntax" for AuthenthicationTypes.None,
AuthenthicationTypes.Delegation, AuthenthicationTypes.FastBind,
AuthenthicationTypes.ReadOnlyServer, AuthenthicationTypes.Sealing.

I get an exception "Die angeforderte Authentifizierungsmethode wird
durch den Server nicht unterstützt" (authenthication method not
supported by server) for AuthenthicationTypes.Secure or if I don't
specify an AuthenthicationType.

Any help is appreciated!
Dorrit


AuthenticationTypes.Anonymous means ... no authentication is performed, so your credentials
are not checked at all. You should specify None as type, this will force Basic
authentication, basically OpenLdap does only support "basic" and "SecureSocketsLayer", other
types are not supported.
Another point is that you better use System.DirectoryServices.Protocols (FCL v2) when
connecting to non Active Directory, OpenLDAP is not AD and the directory schema is not the
same as the AD schema so you better use lower level LDAP API's then the ADSI (wrapped by
SDS).
Following snip illustrates how you can bind using basic authentication.

using System.DirectoryServices.Protocols;
....
using (LdapConnection ldap = new LdapConnection("ldapserverName"))
{
ldap.AuthType = AuthType.Basic;
ldap.Bind(new NetworkCredential("username", "pwd")); // credentials for the
bind, username in upn format
// do whatever you need to do with the store
SearchRequest req = new SearchRequest("cn=....", ....
....
}


Willy.




 
Reply With Quote
 
dorrit.Riemenschneider@communardo.de
Guest
Posts: n/a
 
      11th Jan 2007
OK, I'll try the approach with DirectoryServices.Protocols then. Thanks
for the tip.

Dorrit

Willy Denoyette [MVP] schrieb:

> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> I need to validate a user with username and password against our
> OpenLDAP active directory. This is my code:
>
> Private bool ValidateUser (string username, string password)
> {
> DirectoryEntry userEntry = new DirectoryEntry(
> ldapPath, username, password,
> AuthenticationTypes.Anonymous);
> //Bind to the native AdsObject to force authentication.
>
> Object obj = userEntry.NativeObject;
> DirectorySearcher search = new
> DirectorySearcher(userEntry);
> search.Filter = "(cn=" + username + ")";
> search.PropertiesToLoad.Add("cn");
> SearchResult result = search.FindOne();
> if (result != null)
> return true;
> else
> return false;
> }
>
> The problem is, it returns also true if the username is correct, but
> the password is false.
> It looks like the user is located but not authenthicated.
>
> I have already tried with several AuthenthicationTypes:
> I get an exeption "invalid dn-syntax" for AuthenthicationTypes.None,
> AuthenthicationTypes.Delegation, AuthenthicationTypes.FastBind,
> AuthenthicationTypes.ReadOnlyServer, AuthenthicationTypes.Sealing.
>
> I get an exception "Die angeforderte Authentifizierungsmethode wird
> durch den Server nicht unterstützt" (authenthication method not
> supported by server) for AuthenthicationTypes.Secure or if I don't
> specify an AuthenthicationType.
>
> Any help is appreciated!
> Dorrit
>
>
> AuthenticationTypes.Anonymous means ... no authentication is performed, so your credentials
> are not checked at all. You should specify None as type, this will force Basic
> authentication, basically OpenLdap does only support "basic" and "SecureSocketsLayer", other
> types are not supported.
> Another point is that you better use System.DirectoryServices.Protocols (FCL v2) when
> connecting to non Active Directory, OpenLDAP is not AD and the directory schema is not the
> same as the AD schema so you better use lower level LDAP API's then the ADSI (wrapped by
> SDS).
> Following snip illustrates how you can bind using basic authentication.
>
> using System.DirectoryServices.Protocols;
> ...
> using (LdapConnection ldap = new LdapConnection("ldapserverName"))
> {
> ldap.AuthType = AuthType.Basic;
> ldap.Bind(new NetworkCredential("username", "pwd")); // credentials for the
> bind, username in upn format
> // do whatever you need to do with the store
> SearchRequest req = new SearchRequest("cn=....", ....
> ...
> }
>
>
> Willy.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Authenticate user in OpenLDAP with username and password dorrit.Riemenschneider@communardo.de Microsoft Dot NET Framework 0 5th Jan 2007 11:24 AM
Authenticate user in OpenLDAP with username and password dorrit.Riemenschneider@communardo.de Microsoft Dot NET 0 5th Jan 2007 11:24 AM
How to authenticate username and password in Internet explorer ? =?Utf-8?B?U2h5YW0=?= Windows XP Internet Explorer 0 23rd Mar 2006 09:14 AM
Authenticate Username and Password against active directory in vb.net without LDAP B111Gates Microsoft VB .NET 0 13th Jun 2005 11:17 PM
How to authenticate against Win2000 username/password in a VB.net program. Rvo Microsoft Dot NET 0 15th Dec 2003 10:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:42 PM.