Results 1 to 2 of 2

Thread: How to store an encrypted password to ldap

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    4

    Cool How to store an encrypted password to ldap

    Hello Everybody

    I want to save a SHA-Encrypted password into a ldap database.
    The problem is, that after I updated the new password, the user can't login anymore! How I have to save the password to the ldap database?

    What I do:
    Before saving the User to the ldap I encrypt the Passwort to a SHA string.
    When I look into the LDAP-Database the user have the correct SHA string in BASE64.
    When I try to login always get the error Bad Credentials.

    When I change the password with a external tool the login works.

  2. #2
    Join Date
    Jun 2012
    Posts
    4

    Thumbs up

    I found a solution
    You have to encrypt your password like this:
    public static byte[] encodePassword(String password) {
    MessageDigest md;
    StringBuffer hexString = new StringBuffer();

    try {
    md = MessageDigest.getInstance(SHA);
    } catch (NoSuchAlgorithmException e) {
    log.error("Unexpected error encoding password ", e);
    e.printStackTrace();
    return new byte[0];
    }
    hexString.append("{" + SHA + "}");

    md.reset();
    try {
    md.update(password.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
    log.error("Unexpected error encoding password ", e);
    e.printStackTrace();
    return new byte[0];
    }

    byte[] buff = md.digest();
    hexString.append(CBBase64.binaryToString(buff));
    try {
    return hexString.toString().getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
    log.error("Unexpected error encoding password ", e);
    e.printStackTrace();
    return new byte[0];
    }
    }
    The CBBase64 Class can be found here:
    http://jxplorer.svn.sourceforge.net/...ommons/cbutil/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •