Created
July 28, 2022 08:49
-
-
Save dehidehidehi/637b39cdf95086b7b1003f6d70a63b01 to your computer and use it in GitHub Desktop.
Generates random string non case-sensitive
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
/** 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