Skip to content
Snippets Groups Projects
Commit 5159c792 authored by Sebastian Kürten's avatar Sebastian Kürten
Browse files

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

parent 8c2e2f46
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 { ...@@ -7,18 +7,27 @@ class StringUtils {
private static final Random random = new SecureRandom(); 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) { public static String getRandomString(int length) {
char[] c = new char[length]; char[] c = new char[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
if (random.nextBoolean()) { if (random.nextBoolean()) {
c[i] = (char) ('0' + random.nextInt(10)); c[i] = random(digits);
} else if (random.nextBoolean()) { } else if (random.nextBoolean()) {
c[i] = (char) ('a' + random.nextInt(26)); c[i] = random(letters);
} else { } else {
c[i] = (char) ('A' + random.nextInt(26)); c[i] = random(LETTERS);
} }
} }
return new String(c); 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