Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PrincipalContext.ValidateCredentials(null, null) does not use credentials supplied in the contructor #26009

Closed
gabeluci opened this issue Apr 27, 2018 · 9 comments
Labels
area-System.DirectoryServices documentation Documentation bug or enhancement, does not impact product or test code
Milestone

Comments

@gabeluci
Copy link

This came from a question on Stackoverflow: https://stackoverflow.com/questions/50055073/testing-a-principalcontext-using-validatecredentialsnull-null-behaves-une

The documentation of PrincipalContext.ValidateCredentials(String, String) says:

If the username and password arguments are null, the credentials specified in the constructor are validated.

However, this is not what actually happens. It seems to use the default credentials of the running process, rather than the credentials supplied in the constructor of PrincipalContext.

This can be replicated by running a project under credentials that are untrusted on your domain (like a local computer account) then using this code:

        var ctx = new PrincipalContext(ContextType.Domain, "domain.local", "username", "password");
        var valid = ctx.ValidateCredentials(null, null);

Where "username" and "password" are valid on the domain, of course. After this, valid comes out to be false.

I enabled .NET code debugging and found that the credentials passed in the constructor are never passed along during ValidateCredentials. Instead, the null values are passed along (which are then turned into empty strings once they're fed into NetworkCredential).

However, if I run the process under domain credentials, then ValidateCredentials succeeds.

@karelz
Copy link
Member

karelz commented Apr 27, 2018

I wonder what is the behavior on .NET Framework? Is it same, or does it do what documentation says?

@tquerec
Copy link
Member

tquerec commented Apr 27, 2018

The documentation is incorrect. If NULL as passed as username and password the credentials of the current process are validated. .NET core and .NET framework behave the same.

@karelz
Copy link
Member

karelz commented Apr 27, 2018

Should we fix the docs then? It is simple - just hit edit button on the linked docs page and submit PR.

@tquerec
Copy link
Member

tquerec commented Apr 27, 2018

Opened PR with changes dotnet/dotnet-api-docs#92

@gabeluci
Copy link
Author

Thanks folks.

@gabeluci
Copy link
Author

gabeluci commented Oct 4, 2018

I just happened to look at this again today, and I realized that the updates made back in April weren't entirely accurate.

Right now, it reads like this:

If the username and password arguments are null, the credentials specified in the constructor are validated. If no credential were specified in the constructor, and the username and password parameters are null, this method validates the default credentials for the current principal.

It still makes reference to the "credentials specified in the constructor". In reality, the credentials specified in the constructor make no difference to this method. It should read something like this:

If the username and password arguments are null, this method validates the default credentials for the current principal.

@karelz
Copy link
Member

karelz commented Oct 4, 2018

@gabeluci can you please submit changes directly against docs repo? (there is edit button on doc pages)

@gabeluci
Copy link
Author

gabeluci commented Oct 4, 2018

Sure, I've added dotnet/dotnet-api-docs#580

@tarekgh
Copy link
Member

tarekgh commented Apr 26, 2019

I closing this as it looks the issue is addressed. let's know if this is not the case.

@tarekgh tarekgh closed this as completed Apr 26, 2019
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.DirectoryServices documentation Documentation bug or enhancement, does not impact product or test code
Projects
None yet
Development

No branches or pull requests

5 participants