How to validate a domain user that attribute logonWorkstation has set to a pc RRS feed

  • Question

  • I build a c# projiect to validate windows domain account.When a user that its attribute logonWorkstation set to a pc.user can not validate its account even though hi has enter a correct password.

    static public bool ValidateCredentials(string userName, string password, out string ex)
                //#if DEBUG
                //            ex = string.Empty;
                //            return true;
                ex = string.Empty;
                PrincipalContext principalContext;
                    principalContext = GetPrincipalContext();
                    ex = string.Empty;
                    return principalContext.ValidateCredentials(userName, password);
                catch (Exception exception)
                    ex = exception.Message;
                    return false;

    any one can  help me?


    Friday, December 21, 2018 7:38 AM

All replies

  • Not sure I follow what problem you're having. ValidateCredentials is simply going to verify the UN/PWD are valid for the given context (domain or machine). It has nothing to do with whether login would be successful or not AFAIK. To check that a user could log into a given machine you'd have to use LogonUser. That is, of course, a more expensive call as it would have to login instead of just validating the credentials.

    Alternatively you could also get the user's privileges (taking into account machine or domain) and then check for the appropriate privilege. Unfortunately IIRC you'll need to use P/Invoke to get that information as it isn't available in .NET directly. Note also that having a privilege doesn't mean it is enabled so you have to both check for the privilege and that it is enabled. Depending upon what function you call you'll have to check for enabled or not. Some filter disabled out and others don't.

    Michael Taylor

    Friday, December 21, 2018 3:35 PM
  • Hi Chivas_Tan,

    Thank you for posting here.

    Could you provide the GetPrincipalContext method?

    We are waiting for your updating.

    Best regards,

    Jack J Jun.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, December 24, 2018 8:42 AM