Tuesday, July 17, 2012

Verify user credentials

If you would need to verify user's windows credentials you can use this code:
            // create a "principal context" - e.g. your domain (could be machine, too)
            using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "DOMAIN"))
            {
                // validate the credentials
                bool isValid = pc.ValidateCredentials(@"user", "password");

                if (isValid == true)
                    return "user is valid";
                else
                    return "user is not valid";
            }

No comments:

Post a Comment