ActiveDirectory Authenticating WinForms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?anAybXNmdA==?=

    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(st ring 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.Authentic ationType = AuthenticationT ypes.ServerBind ;
    try {
    object nativeObj = entry.NativeObj ect;
    Console.WriteLi ne(string.Forma t("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?
  • =?Utf-8?B?anAybXNmdA==?=

    #2
    RE: ActiveDirectory Authenticating WinForms

    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.For mat" 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(st ring 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.Authentic ationType = AuthenticationT ypes.ServerBind ;
    try {
    object nativeObj = entry.NativeObj ect;
    Console.WriteLi ne(string.Forma t("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?

    Comment

    Working...