Skip to content

Instantly share code, notes, and snippets.

@kelvinewilliams
Created July 8, 2013 00:37
Show Gist options
  • Save kelvinewilliams/5945507 to your computer and use it in GitHub Desktop.
Save kelvinewilliams/5945507 to your computer and use it in GitHub Desktop.
Simple way to salt passwords. For best results (and consistent sizes for database storage) hash the resulting string.
private static String saltIt(String passphrase) {
String saltChars = "i08q4h0fn23in2034qnvosysag01n40!$#@#$^@#$#ESDGASFXBSDFHDFH2";
char[] salt = saltChars.toCharArray();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(passphrase);
for (char s : salt) {
stringBuilder.append(s);
stringBuilder.append(passphrase);
}
return stringBuilder.toString();
}
@kelvinewilliams
Copy link
Author

Be sure to change the saltChars string before you re-use this code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment