By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

ActiveDirectory Authenticating WinForms

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.