I am trying to change the user password of OpenLDAP from ASP.NET Core Web API using the library Novell.Directory.Ldap
. OpenLDAP is configured on Ubuntu 18.04 with SSL enabled. So I connect using the option SecureSocketLayer = true
and Port = 636
. Following is the code to change the password:
string oldPassword = '"' OldPassword '"';
string newPassword = '"' NewPassword '"';
var oldPasswordbytes = Encoding.Unicode.GetBytes(oldPassword);
var newPasswordbytes = Encoding.Unicode.GetBytes(newPassword);
LdapModification[] modifications = new LdapModification[2];
LdapAttribute deletePassword = new LdapAttribute("unicodePwd", oldPasswordbytes);
modifications[0] = new LdapModification(LdapModification.Delete, deletePassword);
LdapAttribute addPassword = new LdapAttribute("unicodePwd", newPasswordbytes );
modifications[1] = new LdapModification(LdapModification.Add, addPassword);
connection.Modify(userDn, modifications);
This code goes well with the AD domain. But for OpenLDAP it is giving error:
unicodePwd: attribute type undefined
I tried userPassword
instead of unicodePwd
but the same type of error.
Does this error belong to an attribute not exist in OpenLDAP or I cannot use this code for OpenLDAP? How to change the OpenLDAP user password using C# library?
CodePudding user response:
Only Active Directory requires the special format for the password value. For OpenLDAP, just use a regular string without quotes.
Also, OpenLDAP uses the userPassword
attribute.