Created
June 7, 2018 20:46
-
-
Save sayemkcn/6f3c00e701518cc05d9e231e9c5b8ed9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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