Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Password not taking effect with Novell LDAP Modification for Asp.Net Core 2

Tags:

c#

asp.net

ldap

For anyone who can help - I have code working fine in Asp/Net Core 2.0 that can add entries to LDAP using the Novell.Directory.Ldap.NETStandard (2.3.8) library. I also update properties and everything is error free. However when I update a password it doesn't take. I can't login in using the same password I just set through code. I'm wondering if anyone has run into this, do I need to encode it a special way and/or do any additional steps?

Here's what my code looks like - pretty simple and it works without causing an error:

modList.Add(new LdapModification(LdapModification.REPLACE, new LdapAttribute("pwdLastSet", "-1")));

modList.Add(new LdapModification(LdapModification.REPLACE, new LdapAttribute("userPassword", newPassword)));

LdapModification[] mods = new LdapModification[modList.Count];

mods = (LdapModification[])modList.ToArray(typeof(LdapModification));

string dn = String.Format("CN={0},CN={1},DC=WPD,DC=Local", displayName, "Users");

_conn.Modify(dn, mods);

Thanks! Craig

like image 965
CraigsterJ Avatar asked Nov 27 '25 19:11

CraigsterJ


1 Answers

Instead of using "userPassword" attribute, I used "unicodePwd" attribute and changed the encoding, and it worked. The most IMPORTANT thing is to enclose the password in double quotes.

string password = "\"myNewStrongPassword\"";
var encodedBytes = SupportClass.ToSByteArray(Encoding.Unicode.GetBytes(password));
var attributePassword = new LdapAttribute("unicodePwd", encodedBytes);
ldapConnection.Modify(YOUR_DISTINGUISHED_NAME, new LdapModification(LdapModification.REPLACE, attributePassword));
like image 164
Gokulnath Avatar answered Nov 30 '25 07:11

Gokulnath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!