Java Utililty Methods Password Generate

List of utility methods to do Password Generate

Description

The list of methods to do Password Generate are organized into topic(s).

Method

StringgeneratePassword(int length, String combination)
Generates a random password of length equal to length , consisting only of the characters contained in combination .
char[] charArray = combination.toCharArray();
StringBuilder sb = new StringBuilder(length);
Random random = new Random();
for (int i = 0, n = charArray.length; i < length; i++) {
    sb.append(charArray[random.nextInt(n)]);
return sb.toString();
char[]generatePassword(int minLen, int maxLen, int noOfCAPSAlpha, int noOfDigits, int noOfSplChars)
generate Password
if (minLen > maxLen)
    throw new IllegalArgumentException("Min. Length > Max. Length!");
if ((noOfCAPSAlpha + noOfDigits + noOfSplChars) > minLen)
    throw new IllegalArgumentException(
            "Min. Length should be atleast sum of (CAPS, DIGITS, SPL CHARS) Length!");
Random rnd = new Random();
int len = rnd.nextInt(maxLen - minLen + 1) + minLen;
char[] pswd = new char[len];
...
StringgenerateString(final String letters, int length)
Generates quasi-random String of given length.
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++) {
    sb.append(letters.charAt(r.nextInt(letters.length())));
return sb.toString();
StringgenerateString(int length)
generate String
StringBuilder sb = new StringBuilder();
for (int k = 0; k < length; k++) {
    char c = alphabet.charAt(random.nextInt(alphabet.length()));
    sb.append(c);
return sb.toString();
StringgenerateString(int length)
generate String
StringBuffer sb = new StringBuffer();
Random random = new Random();
for (int i = 0; i < length; i++) {
    sb.append(bigChar.charAt(random.nextInt(bigChar.length())));
return sb.toString();
StringgenerateString(int length)
Creates a random string using only lowercase ascii letters, uppercase ascii letters, and digits.
char[] buf = new char[length];
for (int i = 0; i < buf.length; i++) {
    buf[i] = chars.charAt(random.nextInt(chars.length()));
return new String(buf);
StringgenerateString(int length)
Generates a random string with a length of length.
char[] chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
    char c = chars[random.nextInt(chars.length)];
    sb.append(c);
return sb.toString();
StringGenerateString(int Length)
Generate String
char[] buf = new char[Length];
for (int idx = 0; idx < buf.length; ++idx)
    buf[idx] = Symbols[RandomSeed.nextInt(Symbols.length)];
return new String(buf);
StringgenerateString(int maxlength)
Generate a random string of a maximum length.
String s = null;
Random r = new Random();
if (maxlength == 1) {
    int n = 97 + r.nextInt(26);
    char c = (char) n;
    s = Character.toString(c);
} else {
    s = Long.toString(Math.abs(r.nextLong()), 36);
...
StringgenerateString(String alphabet, int length)
generate String
if (alphabet.length() == 0)
    return null;
StringBuilder ret = new StringBuilder(length);
for (int i = 0; i < length; ++i)
    ret.append(alphabet.charAt(random.nextInt(alphabet.length())));
return ret.toString();