473,386 Members | 1,715 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,386 software developers and data experts.

ActiveDirectory Authenticating WinForms

We have PCs out on the Manufacturing floor that have public access and are
always logged in using a public/global profile.

Whenever someone needs to access sensitive information, we want to verify
they have permission by checking their username/password on our Active
Directory server.

How should I authenticate our users using a local Active Directory server? I
have tried the code below, but it returned a COMException 0x80005000 "Unknown
error":

Code:
public static bool Authenticate(string domain, string userName, string
passWord) {
string path = string.Format("LDAP://{0}", domain);
string domUser = domain + @"\" + userName;
DirectoryEntry entry = new DirectoryEntry(string.Format("LDAP://{0}",
path), domUser, passWord);
entry.AuthenticationType = AuthenticationTypes.ServerBind;
try {
object nativeObj = entry.NativeObject;
Console.WriteLine(string.Format("Username '{0}' Authenticated",
userName));
return true;
} catch (COMException e) {
MessageBox.Show(string.Format("Username '{0}' Not Authenticated:\n{1}",
userName, e.Message));
} catch (Exception e) {
MessageBox.Show(string.Format("Username '{0}' Not Authenticated:\n{1}",
userName, e.Message));
}
return false;
}

Could someone offer a suggestion? I tried Googling, but most solutions
appear to be tailored for ASP.NET - we are only using WinForms.

Is ServerBind incorrect?

Whenever I bring up the Windows Login information (CTRL-ALT-DEL), I can see
that my personal username is "ACPINC\cp-jpool" - and this is what I send in
along with my password using the path LDAP://ACPINC", but it does not work.

Our "Know-It-All" System Administrator ...doesn't! He has nearly completed
his extensive 6-month training at one of the prestigious online websites, so
asking him produced me the useless "I don't know" answer.

Could someone offer a suggestion?
Sep 2 '08 #1
1 5204
Ok, I'm an idiot. I fixed it.

I formatted the path originally, but it wasn't working so I had moved the
path outside of the initialization for the DirectoryEntry. The only thing I
forgot was to remove the "string.Format" section whenever I was doing my
"cut-n-paste."

If anyone sees any other problems with my code, please feel free to point
them out.

Regards, and thanks for putting up with my slow brain this morning!
~Joe

"jp2msft" wrote:
We have PCs out on the Manufacturing floor that have public access and are
always logged in using a public/global profile.

Whenever someone needs to access sensitive information, we want to verify
they have permission by checking their username/password on our Active
Directory server.

How should I authenticate our users using a local Active Directory server? I
have tried the code below, but it returned a COMException 0x80005000 "Unknown
error":

Code:
public static bool Authenticate(string domain, string userName, string
passWord) {
string path = string.Format("LDAP://{0}", domain);
string domUser = domain + @"\" + userName;
DirectoryEntry entry = new DirectoryEntry(string.Format("LDAP://{0}",
path), domUser, passWord);
entry.AuthenticationType = AuthenticationTypes.ServerBind;
try {
object nativeObj = entry.NativeObject;
Console.WriteLine(string.Format("Username '{0}' Authenticated",
userName));
return true;
} catch (COMException e) {
MessageBox.Show(string.Format("Username '{0}' Not Authenticated:\n{1}",
userName, e.Message));
} catch (Exception e) {
MessageBox.Show(string.Format("Username '{0}' Not Authenticated:\n{1}",
userName, e.Message));
}
return false;
}

Could someone offer a suggestion? I tried Googling, but most solutions
appear to be tailored for ASP.NET - we are only using WinForms.

Is ServerBind incorrect?

Whenever I bring up the Windows Login information (CTRL-ALT-DEL), I can see
that my personal username is "ACPINC\cp-jpool" - and this is what I send in
along with my password using the path LDAP://ACPINC", but it does not work.

Our "Know-It-All" System Administrator ...doesn't! He has nearly completed
his extensive 6-month training at one of the prestigious online websites, so
asking him produced me the useless "I don't know" answer.

Could someone offer a suggestion?
Sep 2 '08 #2

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

Similar topics

6
by: Smitro | last post by:
Hi, I'm looking for a Tutorial about Authenticating using PHP and Linux User Accounts. Can some one point me in the right direction? Smitro
2
by: bob | last post by:
Hi, Is this the right place to dicuss Visual Studio 2005 and .Net 2? I am try to implement a class (already using Windows Authentication) where I am given a user name and I return a list of...
4
by: Sargas Atum | last post by:
Hi all, I am trying to get the field "lastLogon" out of ActiveDirectory. It should be trivial I thought, but it is not, as I have experienced. private DataRow FillDataRow( DataRow dataRow, ...
3
by: mrwoopey | last post by:
Hi, I am using the example "Authenticate against the Active Directory by Using Forms Authentication and Visual Basic .NET": http://support.microsoft.com/default.aspx?scid=KB;EN-US;326340 ...
4
by: Greg Burns | last post by:
I have built a web app that uses forms authentication. There isn't a "remember me" feature (i.e. the authentication cookie is not permanent). When you close the browser, and open a new one, you...
0
by: dhnriverside | last post by:
Hi guys I want to find out which of my ActiveDirectory users is logged on to a particular ActiveDirectory Computer. I can get what Computer a user is logged on to with ...
0
by: Nandagopal | last post by:
Hi, I am using the example "Authenticate against the Active Directory by Using Forms Authentication and C#": But I am having a problem figuring out the LDAP:// The LDAP:// that I pass looks...
0
by: richardaz | last post by:
I have been working on a project to search for 250,000 different records in ActiveDirectory. The process takes a long time and I have tried everything to make it faster. Currently using...
0
by: myth0s | last post by:
Hi, The question: Is it possible to have two differents ActiveDirectory Membership Provider in web.config and change at run-time from the default provider to the second provider if the first one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.