ActiveDirectory Authenticating WinForms

J

jp2msft

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?
 
J

jp2msft

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top