mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-02-15 08:08:42 -06:00
Start work on shortening event IDs
This commit is contained in:
@@ -11,6 +11,8 @@ import java.util.Random;
|
||||
public class KeyGenerator {
|
||||
private static char[] VALID_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456879".toCharArray();
|
||||
|
||||
private static char[] VALID_CHARS_2 = "abcdefghijklmnopqrstuv0123456789".toCharArray();
|
||||
|
||||
// cs = cryptographically secure
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
public static String csRandomAlphaNumericString(int numChars) {
|
||||
@@ -27,4 +29,34 @@ public class KeyGenerator {
|
||||
}
|
||||
return new String(buff);
|
||||
}
|
||||
|
||||
public static String generateEventId() {
|
||||
SecureRandom secRand = new SecureRandom();
|
||||
Random rand = new Random();
|
||||
char[] buff = new char[9];
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
// reseed rand once you've used up all available entropy bits
|
||||
if ((i % 10) == 0) {
|
||||
rand.setSeed(secRand.nextLong()); // 64 bits of random!
|
||||
}
|
||||
buff[i] = VALID_CHARS_2[rand.nextInt(VALID_CHARS_2.length)];
|
||||
}
|
||||
return "e" + new String(buff);
|
||||
}
|
||||
|
||||
public static String generateAnnouncementId() {
|
||||
SecureRandom secRand = new SecureRandom();
|
||||
Random rand = new Random();
|
||||
char[] buff = new char[9];
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
// reseed rand once you've used up all available entropy bits
|
||||
if ((i % 10) == 0) {
|
||||
rand.setSeed(secRand.nextLong()); // 64 bits of random!
|
||||
}
|
||||
buff[i] = VALID_CHARS_2[rand.nextInt(VALID_CHARS_2.length)];
|
||||
}
|
||||
return "a" + new String(buff);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user