views:

36

answers:

1

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?

A: 

The PrincipalContext class is part of the DirectoryServices namespace. 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.

Dave Swersky
I should note that the validation works fine against other OS (e.g. Win7, Server2003, Server2008) that are not a member of a domain.
Mitch
I'm not sure about Win7, but I believe the Server versions already use a local directory-like service for authentication. That would explain the discrepancy.
Dave Swersky
You're probably right. Ultimately it looks like I'm using this for something that it wasn't intended for.
Mitch