X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Futil%2FRandomToken.java;h=8a11c8f096abcb6868dd15f517382d4636f1a589;hb=15c3594cf26458503691dc1993bdd6b414cf83c6;hp=8e83bb90aab8943b559ef5c450f6cfb762565d47;hpb=b0ab4664edfc6ee90b658bfa662a54dec42879b3;p=gigi.git diff --git a/src/org/cacert/gigi/util/RandomToken.java b/src/org/cacert/gigi/util/RandomToken.java index 8e83bb90..8a11c8f0 100644 --- a/src/org/cacert/gigi/util/RandomToken.java +++ b/src/org/cacert/gigi/util/RandomToken.java @@ -3,21 +3,25 @@ package org.cacert.gigi.util; import java.security.SecureRandom; public class RandomToken { - static SecureRandom sr = new SecureRandom(); - public static String generateToken(int length) { - StringBuffer token = new StringBuffer(); - for (int i = 0; i < length; i++) { - int rand = sr.nextInt(26 * 2 + 10); - if (rand < 10) { - token.append('0' + rand); - } - rand -= 10; - if (rand < 26) { - token.append('a' + rand); - } - rand -= 26; - token.append('A' + rand); - } - return token.toString(); - } + + private static SecureRandom sr = new SecureRandom(); + + public static String generateToken(int length) { + StringBuffer token = new StringBuffer(); + for (int i = 0; i < length; i++) { + int rand = sr.nextInt(26 * 2 + 10); + if (rand < 10) { + token.append((char) ('0' + rand)); + continue; + } + rand -= 10; + if (rand < 26) { + token.append((char) ('a' + rand)); + continue; + } + rand -= 26; + token.append((char) ('A' + rand)); + } + return token.toString(); + } }