繁体   English   中英

有没有没有“ unicodePwd”属性的更改LDAP密码的方法

[英]Is there a way to change LDAP password without having “unicodePwd” attribute

在我的LDAP目录中,我没有名为unicodePwd属性。

我只有我们userPassword

我写了Java来更改userPassword属性。 但是,它将其存储为纯文本。 例如,如果我希望新密码为newpassword

LDAP将其存储为newpassword ,并且不会对其进行哈希处理。

更改后,我无法使用此密码进行身份验证。

我在其中执行此操作的部分代码:

String quotedPassword = "\"" + newPassword + "\"";
            byte[] newUnicodePassword = quotedPassword.getBytes("UTF-16LE");

            //String newpass = new String(pwdArray, "UTF8");
            mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("userPassword", newUnicodePassword));

            // Perform the update
            ctx.modifyAttributes(userName, mods);

我更改了此代码,使其通过了哈希密码,但仍无法验证...

MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(newPassword.getBytes("UTF-16LE"));

            byte byteData[] = md.digest();

            //convert the byte to hex format method 1
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < byteData.length; i++) {
             sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }

            //String newpass = new String(pwdArray, "UTF8");
            mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("userPassword", sb.toString()));

            // Perform the update
            ctx.modifyAttributes(userName, mods);

您必须使用LDAP扩展操作来执行此操作,以便服务器正确处理它,有关详细信息: http : //www.rfc-editor.org/rfc/rfc3062.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM