JAVA implementation of mysql password() function

Here is a quick JAVA implementation of mysql password() function:

public static String MySQLPassword(String plainText)
                  throws UnsupportedEncodingException
{
    byte[] utf8 = plainText.getBytes("UTF-8");
    byte[] test = DigestUtils.sha(DigestUtils.sha(utf8));
    return "*" + convertToHex(test).toUpperCase();
}

This is usefull when you have a table with a user password that is updated with mysql password and needs to be changed to JAVA implementantion. I needed it when i started looking at jasig CAS .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.