473,322 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

AD w/ LDAP

Hi,

I have found some sample code for accessing active directory using the
LDAP provider to check a user's credentials. The sample looks good
but I do not understand the point of two lines.

public bool AuthenticateUser(string domain, string username, string2.
password)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( LDAPPATH,
domainAndUsername, password);
try
{
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
LDAPPATH = result.Path;
}
catch (Exception ex)
{
throw new Exception("Error authenticating user." + ex.Message);
}
return true;
}

Can someone tell me what are the lines;
Object obj = entry.NativeObject;
and
LDAPPATH = result.Path;
are for?

Thanks,

Chandy
Nov 16 '05 #1
2 4817
Chandy,

It doesn't look like obj is used for anything. However, the LDAPPATH
looks like it might be a class-level variable which is being set when the
search is successful. You can probably omit the obj variable, but without
seeing the rest of the class definition, I can't say you should take out
LDAPPATH.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chandy" <ch****@totalise.co.uk> wrote in message
news:5a**************************@posting.google.c om...
Hi,

I have found some sample code for accessing active directory using the
LDAP provider to check a user's credentials. The sample looks good
but I do not understand the point of two lines.

public bool AuthenticateUser(string domain, string username, string2.
password)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( LDAPPATH,
domainAndUsername, password);
try
{
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
LDAPPATH = result.Path;
}
catch (Exception ex)
{
throw new Exception("Error authenticating user." + ex.Message);
}
return true;
}

Can someone tell me what are the lines;
Object obj = entry.NativeObject;
and
LDAPPATH = result.Path;
are for?

Thanks,

Chandy

Nov 16 '05 #2
>public bool AuthenticateUser(string domain, string username, string2.
password)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( LDAPPATH,
domainAndUsername, password);
try
{
Object obj = entry.NativeObject;
This gets the "native", ADSI COM object "behind" your .NET
DirectoryEntry. This is of type IADs or any inherited type (e.g.
IADsUser for a user object). You probably don't really need this,
there are a few more advanced functions that can only be used with a
legacy-style ADSI COM object (rather than the .NET DirectoryEntry
object).
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
LDAPPATH = result.Path;


You are searching your directory for a particular user, given the
NetBIOS domain name, and your "pre-Win2000" user name (also known as
SAMAccountName), something like "SAMPLE\JohnDoe".

What you get back from LDAP / AD when you do a search, by looking at
the .Path of the search result, is the LDAP-style distinguished name
of the user object, e.g. something like:

cn=John Doe,ou=Research,ou=HQ,dc=sample,dc=com

Marc

================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Nov 16 '05 #3

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

Similar topics

5
by: dmcconkey | last post by:
Hi folks, I've been searching for a while and haven't found my specific question anywhere else. If this has already been asked, please accept my appologies and point me to the appropriate...
7
by: Amar | last post by:
I am trying to connect to my college LDAP directory using ASP.NET. This LDap does not have security as it returns only user demographic information. i do not need to bind with a username or...
1
by: Angel | last post by:
Hello all - I have a LDAP service running on a NT4 box (not a mbr of my AD domain), I'd like to extract the users/attributes from that LDAP service and populate my AD domain with those users and...
4
by: m96 | last post by:
hi, i'm trying to make a query to a ldap server (version v2 or v3 doen't matter) with c#. the query works just fine but the problem is that i can't read the custom attributes/fields, since .net...
4
by: Terry Miller | last post by:
I have DB2 V8.2 loaded on a Redhat Enterprise Linux version 3 (RHEL 3) box. RHEL is configured to talk to LDAP for authenticaton besides the local passwd file. I can verify this by executing an su...
2
by: duncan beaumont | last post by:
Hi, - SQLserver 2000 - Yellowfin 2.4 - Windows 2003 server I have been asked to investigate seting up LDAP authentication to access our Yellowfin reporting.
5
by: Jed Parsons | last post by:
Hi, authenticates a user against our ldap server.: User types in name and password, and module sees if name and password check out right with the ldap server. I see that it's pretty...
3
by: sallas | last post by:
Hi, I have a simple LDAPS script: #!/usr/bin/python2.3 import sys import ldap if __name__ == '__main__': ldap.set_option(ldap.OPT_DEBUG_LEVEL,255)
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
0
by: Sells, Fred | last post by:
I'm running python 2.5 (or 2.4) in an XP environment. I downloaded and installed the .dll's from OpenLDAP-2.4.8+OpenSSL-0.9.8g-Win32.zip and copied the .dll's in c:/windows/system32 as instructed...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.