473,698 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Authenticate user in OpenLDAP with username and password

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,
AuthenticationT ypes.Anonymous) ;
//Bind to the native AdsObject to force authentication.

Object obj = userEntry.Nativ eObject;
DirectorySearch er search = new
DirectorySearch er(userEntry);
search.Filter = "(cn=" + username + ")";
search.Properti esToLoad.Add("c n");
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 Authenthication Types:
I get an exeption "invalid dn-syntax" for Authenthication Types.None,
Authenthication Types.Delegatio n, Authenthication Types.FastBind,
Authenthication Types.ReadOnlyS erver, Authenthication Types.Sealing.

I get an exception "Die angeforderte Authentifizieru ngsmethode wird
durch den Server nicht untersttzt" (authenthicatio n method not
supported by server) for Authenthication Types.Secure or if I don't
specify an Authenthication Type.

Any help is appreciated!
Dorrit

Jan 5 '07 #1
3 26646
<do************ ********@commun ardo.dewrote in message
news:11******** *************@v 33g2000cwv.goog legroups.com...
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,
AuthenticationT ypes.Anonymous) ;
//Bind to the native AdsObject to force authentication.

Object obj = userEntry.Nativ eObject;
DirectorySearch er search = new
DirectorySearch er(userEntry);
search.Filter = "(cn=" + username + ")";
search.Properti esToLoad.Add("c n");
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 Authenthication Types:
I get an exeption "invalid dn-syntax" for Authenthication Types.None,
Authenthication Types.Delegatio n, Authenthication Types.FastBind,
Authenthication Types.ReadOnlyS erver, Authenthication Types.Sealing.

I get an exception "Die angeforderte Authentifizieru ngsmethode wird
durch den Server nicht untersttzt" (authenthicatio n method not
supported by server) for Authenthication Types.Secure or if I don't
specify an Authenthication Type.

Any help is appreciated!
Dorrit

Jan 5 '07 #2
<do************ ********@commun ardo.dewrote in message
news:11******** *************@v 33g2000cwv.goog legroups.com...
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,
AuthenticationT ypes.Anonymous) ;
//Bind to the native AdsObject to force authentication.

Object obj = userEntry.Nativ eObject;
DirectorySearch er search = new
DirectorySearch er(userEntry);
search.Filter = "(cn=" + username + ")";
search.Properti esToLoad.Add("c n");
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 Authenthication Types:
I get an exeption "invalid dn-syntax" for Authenthication Types.None,
Authenthication Types.Delegatio n, Authenthication Types.FastBind,
Authenthication Types.ReadOnlyS erver, Authenthication Types.Sealing.

I get an exception "Die angeforderte Authentifizieru ngsmethode wird
durch den Server nicht untersttzt" (authenthicatio n method not
supported by server) for Authenthication Types.Secure or if I don't
specify an Authenthication Type.

Any help is appreciated!
Dorrit
AuthenticationT ypes.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 "SecureSocketsL ayer", other
types are not supported.
Another point is that you better use System.Director yServices.Proto cols (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.Director yServices.Proto cols;
....
using (LdapConnection ldap = new LdapConnection( "ldapserverName "))
{
ldap.AuthType = AuthType.Basic;
ldap.Bind(new NetworkCredenti al("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.


Jan 5 '07 #3
OK, I'll try the approach with DirectoryServic es.Protocols then. Thanks
for the tip.

Dorrit

Willy Denoyette [MVP] schrieb:
<do************ ********@commun ardo.dewrote in message
news:11******** *************@v 33g2000cwv.goog legroups.com...
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,
AuthenticationT ypes.Anonymous) ;
//Bind to the native AdsObject to force authentication.

Object obj = userEntry.Nativ eObject;
DirectorySearch er search = new
DirectorySearch er(userEntry);
search.Filter = "(cn=" + username + ")";
search.Properti esToLoad.Add("c n");
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 Authenthication Types:
I get an exeption "invalid dn-syntax" for Authenthication Types.None,
Authenthication Types.Delegatio n, Authenthication Types.FastBind,
Authenthication Types.ReadOnlyS erver, Authenthication Types.Sealing.

I get an exception "Die angeforderte Authentifizieru ngsmethode wird
durch den Server nicht untersttzt" (authenthicatio n method not
supported by server) for Authenthication Types.Secure or if I don't
specify an Authenthication Type.

Any help is appreciated!
Dorrit
AuthenticationT ypes.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 "SecureSocketsL ayer", other
types are not supported.
Another point is that you better use System.Director yServices.Proto cols (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.Director yServices.Proto cols;
...
using (LdapConnection ldap = new LdapConnection( "ldapserverName "))
{
ldap.AuthType = AuthType.Basic;
ldap.Bind(new NetworkCredenti al("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.
Jan 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2319
by: Michael Glaesemann | last post by:
Hello all, Recently I've been thinking about different methods of managing users that log into a PostgreSQL-backed application. The users I'm thinking of are not necessarily DBAs: they're application users that really shouldn't even be aware that they are being served by the world's most advanced open source database server. I appreciate any thoughts or feedback people may have, as I'm trying to decide which is the most appropriate way...
13
12951
by: ALI-R | last post by:
I know how to authenticate to a webservice using either of these ways(Assuming that rService represents the webservice): 1) rService.Credentials = new System.Net.NetworkCredential("username","password","domainName"); 2)rService.Credentials = System.Net.CredentialCache.DefaultCredentials; My question is that is there a way to authenticate to a user using WindowsIdentity ???
1
4532
by: EricRybarczyk | last post by:
I am starting a rewrite of an existing Classic ASP web site in ASP.NET 2.0. The existing ASP application has several types of users, each with a separate login process (separate login page, separate DB tables, etc). For one of these user types, the current application has an additional input field required for login… they have a username, password, and another “location code” field. Please don’t make me explain or justify this…...
0
1274
by: dorrit.Riemenschneider | last post by:
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.
1
13248
by: fomalhaut | last post by:
Hi All, I'm builing an application that requires domain admin access to run, and I'm trying to allow for the application to be run as a normal user and allow the user to provide it with a username/password that has the access. I have a method that will check if the username/password is correct, however, it will only authenticate the user running the program...
1
3506
by: Michael Howes | last post by:
I would think this would be very, very easy but in the 50 searches I've done I haven't found anything. If our application requires login and that user/password be a local windows account or more detailed, a user that has been added to the Power Users group that is either a local account or a active directory account how do I authenticate? I've found code that seems to do this against Active Directory
2
5546
by: Jagath84 | last post by:
Hi all, I want to update openldap directory from c#. I used following code for make Directory entry as below. public static DirectoryEntry GetDirectoryEntry() { DirectoryEntry de = new DirectoryEntry(); de.Path = "LDAP://192.248.8.239/OU=People,DC=example,DC=com"; de.AuthenticationType = AuthenticationTypes.ServerBind;
4
2283
by: Jon | last post by:
I am modifying an app for a customer in ASP.Net 1.1. The app is running on a server outside their network, yet they want to authenticate users against their internal active directory set up (they will open the necessary ports). So, I have a simple login page with username and password, and then I will authenticate that credentials entered against their AD server. I am having a real hard time figuring this out. We can't use Windows Forms...
3
6054
by: kurtk | last post by:
I had a question about the use of the HTTP header 'WWW-Authenticate' in PHP scripts. For example, the script below sends the header 'WWW- Authenticate: Basic Realm="Secret Stash"', followed by the header 'HTTP/1.0 401 unauthorized', to force the web browser to display a username/password dialog. The script then calls exit(). I don't understand how the script gets re-invoked (after the username and password have been supplied in the...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.