Skip to content

Instantly share code, notes, and snippets.

@sayemkcn
Created June 7, 2018 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayemkcn/6f3c00e701518cc05d9e231e9c5b8ed9 to your computer and use it in GitHub Desktop.
Save sayemkcn/6f3c00e701518cc05d9e231e9c5b8ed9 to your computer and use it in GitHub Desktop.
/**
* Created by sayem on 14-Jul-17.
*/
public class PasswordUtil {
public static int PASS_MIN_SIZE = 6;
public static final int CRYPTO_STRENGTH = 512;
public enum EncType {SHA_ENCODER, BCRYPT_ENCODER}
// public static ShaPasswordEncoder getShaPasswordEncoder() {
// return new ShaPasswordEncoder(CRYPTO_STRENGTH);
// }
public static BCryptPasswordEncoder getBCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
public static String encryptPassword(String password, EncType encryptType, String salt) throws Exception {
if (password == null) throw new NullPasswordException("Password can not be empty!");
if (encryptType.equals(EncType.SHA_ENCODER)) {
if (salt != null)
return getShaPasswordEncoder().encode(password, salt);
else getShaPasswordEncoder().encode(password);
} else if (encryptType.equals(EncType.BCRYPT_ENCODER))
return getBCryptPasswordEncoder().encode(password);
return getBCryptPasswordEncoder().encode(password);
}
public static SymfonySha512PasswordEncoder getShaPasswordEncoder() {
return new SymfonySha512PasswordEncoder();
}
// public static String encryptPassword(String password, String salt) throws Exception {
// return getPasswordEncoder().encode(password, salt);
// }
//
// public static String encryptPassword(String password) {
// return getPasswordEncoder().encode(password);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment