DirectoryEntry.Password Property

Definition

Sets the password to use when authenticating the client.

C#
public string? Password { set; }
C#
[System.ComponentModel.Browsable(false)]
[System.DirectoryServices.DSDescription("DSPassword")]
public string Password { get; set; }
C#
[System.ComponentModel.Browsable(false)]
[System.DirectoryServices.DSDescription("DSPassword")]
public string Password { set; }
C#
public string Password { set; }

Property Value

The password to use when authenticating the client.

Attributes

Examples

The following example demonstrates the Username and Password properties of the DirectoryEntry class. This example gets the user-specified DirectoryEntry and the Path of all its Children.

C#
String myADSPath = "LDAP://onecity/CN=Users,
         DC=onecity,DC=corp,DC=fabrikam,DC=com";

// Create an Instance of DirectoryEntry.
DirectoryEntry myDirectoryEntry = new DirectoryEntry(myADSPath);
myDirectoryEntry.Username = UserName;
myDirectoryEntry.Password = SecurelyStoredPassword;

// Get the Child ADS objects.
Console.WriteLine("The Child ADS objects are:");
foreach(DirectoryEntry myChildDirectoryEntry in myDirectoryEntry.Children)
   Console.WriteLine(myChildDirectoryEntry.Path);

Remarks

You can set the Username and Password properties to specify alternate credentials with which to access the information in Active Directory Domain Services. Any other DirectoryEntry objects retrieved from this instance (for example, through Children) are automatically created with the same alternate credentials.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also