Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/1169#discussion_r50831291
--- Diff:
brooklyn-server/utils/common/src/main/java/org/apache/brooklyn/util/text/Identifiers.java
---
@@ -91,15 +105,53 @@ public static String makeRandomId(int l) {
return new String(id);
}
+ /**
+ *
+ * @param length of password to be returned
+ * @return randomly generated password containing at least one of each
upper case,
+ * lower case, numeric, and non alpha-numeric characters. Hopefully
this is acceptible
+ * for most password schemes.
+ */
+ public static String makeRandomPassword(final int length) {
+ return makeRandomPassword(length, UPPER_CASE_ALPHA,
LOWER_CASE_ALPHA, NUMERIC, NON_ALPHA_NUMERIC, PASSWORD_VALID_CHARS);
+ }
+
+ /**
+ * A fairly slow but hopefully secure way to randomly select
characters for a password
+ * Takes a pool of acceptible characters using the first set in the
pool for the first character,
+ * second set for the second character, ..., nth set for all remaining
character.
+ *
+ * @param length length of password
+ * @param passwordValidCharsPool pool of acceptable character sets
+ * @return a randomly generated password
+ */
+ public static String makeRandomPassword(final int length, String...
passwordValidCharsPool) {
+ Preconditions.checkState(length >= passwordValidCharsPool.length);
+ int l = 0;
+
+ char[] id = new char[length];
+
+ for(int i = 0; i < passwordValidCharsPool.length; i++){
+ id[l++] = pickRandomCharFrom(passwordValidCharsPool[i]);
+ }
+
+ String remainingValidChars =
passwordValidCharsPool[passwordValidCharsPool.length - 1];
--- End diff --
I'd concatenate all of the `passwordValidCharsPool` (optionally removing
duplicate chars!), and choose the rest of the letters from that. But no strong
feelings.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---