Export (0) Print
Expand All

PrincipalContext.ValidateCredentials Method (String, String, ContextOptions)

Creates the connections to the server and returns a Boolean value that specifies whether the specified user name and password are valid. This method performs fast credential validation of the username and password.

Namespace:  System.DirectoryServices.AccountManagement
Assembly:  System.DirectoryServices.AccountManagement (in System.DirectoryServices.AccountManagement.dll)

public bool ValidateCredentials(
	string userName,
	string password,
	ContextOptions options


Type: System.String

The username that is validated on the server.

Type: System.String

The password that is validated on the server.

Type: System.DirectoryServices.AccountManagement.ContextOptions

A combination of one or more ContextOptions enumeration values the options used to bind to the server. This parameter can only specify Simple bind with or without SSL, or Negotiate bind.

Return Value

Type: System.Boolean
true if the credentials are valid; otherwise false.


The options parameter must specify Negotiate when the context type is [T:System.DirectoryServices.AccountManagement.ContextType.Machine.]

The ValidateCredentials method binds to the server specified in the constructor. If the username and password parameters 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.

.NET Framework

Supported in: 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft