簡體   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