Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6961555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:32:43+00:00 2026-05-27T15:32:43+00:00

I currently use LogonUser() to authenticate my user’s username and password on my local

  • 0

I currently use LogonUser() to authenticate my user’s username and password on my local domain at the office and it works great for what i need it to do.

Since I developed the app I now need to make it work over my VPN. It seems LogonUser() will not work with REMOTELY validating credentials. Or will it? Is it possible to use LogonUser() to validate a user’s credentials on a REMOTE domain account?

I have read in some places that using LOGON32_LOGON_NEW_CREDENTIALS for the 4th param (login type) and LOGON32_PROVIDER_WINNT50 for the 5th param (provider) would do the trick. But every time I try that I ALWAYS get success… I can supply a bogas user and pass and it will work every time :(.

Ideas?


Edit – Added Notes

Tried to use this function but I kept getting the exception telling me the user/pass was bad.

    public bool Win2kCredentialsIsValid(string domain, string username, string password)
    {
        string adPath = "LDAP://" + domain + "/rootDSE";
        DirectoryEntry adRoot = new DirectoryEntry(adPath, domain + "\\" + username, password, AuthenticationTypes.ReadonlyServer);
        try
        {
            object o = adRoot.Properties["defaultNamingContext"];
        }
        catch
        {
            return false;
        }
        return true;
    }

—
Edit – Added More Notes

OK so I tried yet another example just to get it to work and started down this path, and there are a few things to note…

  • MyServerHostName is exactly that, my server’s hostname. EX: ‘Server01’.
  • My domain name in this example is ‘MyDomain.local’
  • So that makes my FQN for the server ‘Server01.MyDomain.local’

I tried to make this work and got the following error…

The supplied context type does not match the server contacted. The server type is Domain.

This errored out at : var context = new PrincipalContext(ContextType.ApplicationDirectory, “MyServerHostName:389”, “DC=MyDomain,DC=local”))

    private bool CheckADCredentials()
    {
        bool bResults;
        using (var context = new PrincipalContext(ContextType.ApplicationDirectory,
            "MyServerHostName:389",
            "DC=MyDomain,DC=local"))
        {
            var username = "firstname.lastname";
            var email = "firstname.lastname@MyServerHostName";
            var password = "123456";
            var user = new UserPrincipal(context)
            {
                Name = username,
                EmailAddress = email
            };
            user.SetPassword(password);
            user.Save();
            if (context.ValidateCredentials(username, password, ContextOptions.SimpleBind))
            {
                bResults = true;
            }
            else
            {
                bResults = false;
            }

            user.Dispose();
        }

        return bResults;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:32:43+00:00Added an answer on May 27, 2026 at 3:32 pm

    I ended up going with a different solution. Instead of trying to validate a user’s account on a domain that my PC was not connected to I ended up caching my domain credentials in the database and just built a salted MD5 type encrypt function so it would make it hard .. er.. for someone to crack it. 😉

    Now I just validate against cached credentials in the database when working remotely… It just required the user to first login on the domain but then the user can use it remotely day and night. 😉

    Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to impersonate a user using C#. I use the LogonUser Win32 API.
I currently use my local web server to allow costumers to preview some applications
I currently use Authlogic in a web-app to handle user authentication, but have now
Hallo. I need know user name of user which run browser. If I use
I currently use Devise for user registration/authentication in a Rails project. When a user
We currently use Castle Windsor to manage dependency injection in our web applications. The
I currently use nant, ccnet (cruise control), svn, mbunit. I use msbuild to do
I currently use a DataTable to get results from a database which I can
I currently use subversion for my version control via AhnkSVN and Visual Studio. I
I currently use AnkhSVN to integrate subversion into Visual Studio. Is there any reason

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.