Created
April 8, 2020 19:34
-
-
Save flamencist/45ecead51bed9089c50ee1c6ef5cf577 to your computer and use it in GitHub Desktop.
reset password using ldap4net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using(var connection = new LdapConnection()) | |
{ | |
connection.Connect(); | |
connection.TrustAllCertificates(); | |
connection.Bind(); | |
var attribute = new DirectoryModificationAttribute() | |
{ | |
Name = "unicodePwd", | |
LdapModOperation = Native.LdapModOperation.LDAP_MOD_REPLACE | |
}; | |
string password = "\"strongPassword\""; | |
byte[] encodedBytes = System.Text.Encoding.Unicode.GetBytes(password); | |
attribute.Add<byte[]>(encodedBytes); | |
var response = (ModifyResponse)connection.SendRequest(new ModifyRequest("CN=yourUser,CN=Users,dc=dc,dc=local", attribute)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment