I’m using PrinciaplContext.ValidateCredentials to validate a set of credentials against the local machine:
string account = Context.ReadLine();
string pass = Context.ReadLine();
using (var context = new PrincipalContext(ContextType.Machine))
{
bool valid = context.ValidateCredentials(account, pass);
Console.WriteLine("valid: " + (valid ? "true" : "false"));
}
The console application is executing as Administrator and I’m trying to validate the administrator account/password. The machine is running Windows XP and is not part of a domain.
Running the same code on a different Windows XP machine that is part of a domain always returns true regardless of the password being correct or incorrect. If I use ContextType.Domain specifying the domain the account correctly validates.
Does ValidateCredentials just not work in Machine context against XP? Is there something else wrong I’m not accounting for here?
The
PrincipalContextclass is part of theDirectoryServicesnamespace. It would stand to reason that without a domain, there is no directory. Therefore the call to authenticate against a directory will fail if the XP machine is not a member of a domain.