I have read a post on StackOverFlow.com that was really simple and infromative, that I loved to share using a blog post.
The Post was like this :
Hello I am looking for a way to produce the same result as with MySQL‘s PASSWORD function in Java. There are a Implementation of MySQL’s PASSWORD() Function in Java code?
For example:
Password: 123 in MySQLPASSWORD (’123 ‘) -> *23AE809DDACAF96AF0FD78ED04B6A265E05AA257
And the perfect reply for the post was this :
According to the answer pointed to by @ypercube, MySQL PASSWORD() is just sha1, applied twice.
Using Apache Commons Codec:
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();
}
And that is all.
Resources