Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dehidehidehi/637b39cdf95086b7b1003f6d70a63b01 to your computer and use it in GitHub Desktop.
Save dehidehidehi/637b39cdf95086b7b1003f6d70a63b01 to your computer and use it in GitHub Desktop.
Generates random string non case-sensitive
/** Generates random string non-case-sensitive alphanumeric, and special chars **/
public static String generateCommonLangRandomString() {
String upperCaseLetters = RandomStringUtils.random(4, 65, 90, true, true);
String lowerCaseLetters = RandomStringUtils.random(4, 97, 122, true, true);
String numbers = RandomStringUtils.randomNumeric(4);
String specialChar = RandomStringUtils.random(2, 33, 47, false, false);
String totalChars = RandomStringUtils.randomAlphanumeric(2);
String combinedChars = upperCaseLetters.concat(lowerCaseLetters).concat(numbers)
.concat(specialChar)
.concat(totalChars);
List<Character> pwdChars = combinedChars.chars().mapToObj(c -> (char) c).collect(Collectors.toList());
Collections.shuffle(pwdChars);
String password = pwdChars.stream().collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
return password;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment