/** * It encodes/obfuscates a password and adds a human readable prefix that clarifies it. * * @param passwordInPlainText * @return a String containing the encoded password */ public static String encodePasswordWithPrefix(final String passwordInPlainText) { if (hasPrefix(passwordInPlainText)) { return passwordInPlainText; } return PREFIX + encodePassword(passwordInPlainText); }
private String encodePassword(final String password) { if (password == null) { return null; } return SecurityUtils.encodePasswordWithPrefix(password); }
private String getPasswordVariable(final String key, final String valueIfNull) { final String possiblyEncodedPassword = getStringVariable(key, valueIfNull); if (possiblyEncodedPassword == null) { return null; } if (SecurityUtils.hasPrefix(possiblyEncodedPassword)) { return SecurityUtils.decodePasswordWithPrefix(possiblyEncodedPassword); } return possiblyEncodedPassword; }
/** * It decodes/deobfuscates an encoded password with a human readable prefix. * * @param encodedPasswordWithPrefix * @return a String containing the decoded password */ public static String decodePasswordWithPrefix(final String encodedPasswordWithPrefix) { if (encodedPasswordWithPrefix == null) { return null; } if (hasPrefix(encodedPasswordWithPrefix)) { return decodePassword(encodedPasswordWithPrefix.substring(PREFIX.length())); } else { return encodedPasswordWithPrefix; } }
/** * Encodes/obfuscates a password. Although this does not prevent actual * hacking of password, it does remove the obvious threats of having * passwords stored as clear text. * * @param password * @return a String containing the encoded password */ public static String encodePassword(final String password) { if (password == null) { return null; } return encodePassword(password.toCharArray()); }