Skip to content

Instantly share code, notes, and snippets.

@viksit
Created September 20, 2013 21:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viksit/6644289 to your computer and use it in GitHub Desktop.
Save viksit/6644289 to your computer and use it in GitHub Desktop.
Java equivalent of the MySQL PASSWORD() function
/**
* http://stackoverflow.com/questions/868482/simulating-mysqls-password-encryption-using-net-or-ms-sql
* http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function_password
**/
public static String MySQLPassword(String plainText) throws UnsupportedEncodingException {
byte[] utf8 = plainText.getBytes("UTF-8");
return "*" + DigestUtils.shaHex(DigestUtils.sha(utf8)).toUpperCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment