Skip to content
Snippets Groups Projects
Commit ac245b38 authored by Torsten Grote's avatar Torsten Grote
Browse files

Merge branch 'avoid-ambigious-characters' into 'master'

Avoid letters 0,O,l,I for wifi names and passwords

See merge request !4
parents dbf6f241 5159c792
No related branches found
No related tags found
1 merge request!4Avoid letters 0,O,l,I for wifi names and passwords
......@@ -7,18 +7,27 @@ class StringUtils {
private static final Random random = new SecureRandom();
private static String digits = "123456789"; // avoid 0
private static String letters = "abcdefghijkmnopqrstuvwxyz"; // avoid l
private static String LETTERS = "ABCDEFGHJKLMNPQRSTUVWXYZ"; // avoid I, O
public static String getRandomString(int length) {
char[] c = new char[length];
for (int i = 0; i < length; i++) {
if (random.nextBoolean()) {
c[i] = (char) ('0' + random.nextInt(10));
c[i] = random(digits);
} else if (random.nextBoolean()) {
c[i] = (char) ('a' + random.nextInt(26));
c[i] = random(letters);
} else {
c[i] = (char) ('A' + random.nextInt(26));
c[i] = random(LETTERS);
}
}
return new String(c);
}
private static char random(String universe)
{
return universe.charAt(random.nextInt(universe.length()));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment