Skip to content

Instantly share code, notes, and snippets.

@flamencist
Created April 8, 2020 19:34
Show Gist options
  • Save flamencist/45ecead51bed9089c50ee1c6ef5cf577 to your computer and use it in GitHub Desktop.
Save flamencist/45ecead51bed9089c50ee1c6ef5cf577 to your computer and use it in GitHub Desktop.
reset password using ldap4net
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