Search code examples
c#.netactive-directorydirectoryservicesprincipalcontext

Calling ValidateCredentials Results In False (With Known Correct Username/Password), Event 4625 Showing On Domain Server


I am making a very simple call to PrincipalContext.ValidateCredentials under the domain context that is resulting in a false-negative for an unknown reason.

using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "DOMAINNAME"))
            {
                bool isValid = pc.ValidateCredentials("username", "password");
                Console.WriteLine(isValid);
            }

When I view the security audit on the AD server, it shows an audit failed event with Event ID 4625, claiming that the user does not have permission to log into the machine. I can log in to a terminal server joined to this domain using these credentials. This is preceded with a successful audit for the account that I'm running the application under, and I'm able to validate credentials for other users successfully. I'm not able, however, to find any difference whatsoever between accounts that successfully validate and those that do not, they are part of all the same domain security groups.

An account failed to log on.

Subject: Security ID: NULL SID Account Name: - Account Domain: - Logon ID: 0x0

Logon Type: 3

Account For Which Logon Failed: Security ID: NULL SID Account Name: [REDACTED] Account Domain:

Failure Information: Failure Reason: User not allowed to logon at this computer. Status: 0xC000006E Sub Status: 0xC0000070

Process Information: Caller Process ID: 0x0 Caller Process Name: -

Network Information: Workstation Name: [REDACTED] Source Network Address: [REDACTED] Source Port: 62667

Detailed Authentication Information: Logon Process: NtLmSsp Authentication Package: NTLM Transited Services: - Package Name (NTLM only): - Key Length: 0

This event is generated when a logon request fails. It is generated on the computer where access was attempted.

The Subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe.

The Logon Type field indicates the kind of logon that was requested. The most common types are 2 (interactive) and 3 (network).

The Process Information fields indicate which account and process on the system requested the logon.

The Network Information fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases.

The authentication information fields provide detailed information about this specific logon request. - Transited services indicate which intermediate services have participated in this logon request. - Package name indicates which sub-protocol was used among the NTLM protocols. - Key length indicates the length of the generated session key. This will be 0 if no session key was requested.

I seem to be losing my mind here, any help that can be provided would be greatly appreciated. I would consider using an alternative to PrincipalContext if one exists at this point.


Solution

  • As you confirmed in this question's comment section, the user account was bound to login to a specific set of computers, which didn't include the DC servers, which is why your ValidateCredentials was not working.

    @Am_I_Helpful Yes, you're exactly right, that is the issue. If I change the value for the user to log on to all servers, it works correctly and returns true. I guess my understanding of how ValidateCredentials works in the domain context isn't correct, I assumed if it was a valid, unlocked account it would return true. They actually need the domain server in their Log On to server list?

    Yes, if you've to check for the credentials (authentication), then you do need to include the domain controllers of the domain in the user's logon-Workstations list of systems!