0

I'm using the following code to authenticate users on my web service:

using (PrincipalContext context = new PrincipalContext(ContextType.Domain, domain))
{
    return context.ValidateCredentials(userName, password);
}

The obstacle I'm running into is that the first call to ValidateCredentials() is returning false but subsequent calls return true. I placed a breakpoint at this line and in the Intermediate window I see the same results: first call returns false, second returns true, even though nothing was changed (by me) between calls.

The 'domain' is String.Empty but I've also tried it with the actual domain name and get the same results.

I'm not that versed in network administration so any help would be appreciated,

skaffman
  • 398,947
  • 96
  • 818
  • 769
Nick Gotch
  • 9,167
  • 14
  • 70
  • 97

1 Answers1

0

I had the a similar problem with a program to control other machine process's.

I had a piece of code that stalls until login method succeded:

do
{
}
while(!login(usrname, pass));

it does not explain whatever studd is happening but it solved my issue...

Luiscencio
  • 3,855
  • 13
  • 43
  • 74
  • 1
    Does the ValidateCredentials() call increment the user's password retry count? (See http://stackoverflow.com/questions/1899724/how-do-i-reset-password-retry-count-for-a-user-in-the-gpu-using-c) I don't want to inadvertently lock users out doing something like this. If all else fails I may do something like this with a sleep & attempt counter in the do{}. – Nick Gotch Mar 19 '10 at 13:42
  • That smells bad. This solved the issue for me: http://stackoverflow.com/a/11019430/125406 – Michael Silver May 29 '15 at 20:10