So you want to validate local users and Google pointed you towards using ValidateCredentials under PrincipalContext, something like this

using (PrincipalContext pc = new PrincipalContext(ContextType.Machine))
{
    // validate the credentials
    if (pc.ValidateCredentials(username, password))
    {
        //CORRECT
    }
    else
    {
        //INCORRECT
    }
}

And this is working fine when you supply the correct credentials but when you supply the wrong credentials it can take a while (few seconds) to run and that is unacceptable?..  Yes, I ran into that problem and spent some time trying to figure out what was wrong .. then I decided to test the code on a machine that is outside the domain and the problem vanished.

My guess, and this is just a hunch, is that even if you supply .Machine as ContextType the ValidateCredentials is also validating against the Domain Controller and that is what is taking so long,  I didn’t bother looking into this problem any further than this so if you are developing this on a machine that is part of a Domain and the end location is a machine that isn’t, then you can always try your code on a machine that is outside the domain and see if this will become a problem there.

Tagged with: