Code review
What to look for
import java.util.Random;
public class InsecureTokenGenerator {
public static void main(String[] args) {
// Insecure: predictable seed
long seed = System.currentTimeMillis();
Random random = new Random(seed);
StringBuilder token = new StringBuilder();
for (int i = 0; i < 16; i++) {
// Insecure random value
int val = random.nextInt(36);
if (val < 10) {
token.append((char) ('0' + val));
} else {
token.append((char) ('a' + (val - 10)));
}
}
System.out.println("Generated token: " + token.toString());
}
}Last updated