diff --git a/src/main/java/it/stiglianostudio/scadenziario/service/util/RandomUtil.java b/src/main/java/it/stiglianostudio/scadenziario/service/util/RandomUtil.java index dc04d02..0b01fe1 100644 --- a/src/main/java/it/stiglianostudio/scadenziario/service/util/RandomUtil.java +++ b/src/main/java/it/stiglianostudio/scadenziario/service/util/RandomUtil.java @@ -2,23 +2,34 @@ import org.apache.commons.lang3.RandomStringUtils; +import java.security.SecureRandom; + /** * Utility class for generating random Strings. */ public final class RandomUtil { + private static final SecureRandom SECURE_RANDOM = new SecureRandom(); private static final int DEF_COUNT = 20; + static { + SECURE_RANDOM.nextBytes(new byte[64]); + } + private RandomUtil() { } + private static String generateRandomAlphanumericString() { + return RandomStringUtils.random(DEF_COUNT, 0, 0, true, true, null, SECURE_RANDOM); + } + /** * Generate a password. * * @return the generated password */ public static String generatePassword() { - return RandomStringUtils.randomAlphanumeric(DEF_COUNT); + return generateRandomAlphanumericString(); } /** @@ -27,7 +38,7 @@ public static String generatePassword() { * @return the generated activation key */ public static String generateActivationKey() { - return RandomStringUtils.randomNumeric(DEF_COUNT); + return generateRandomAlphanumericString(); } /** @@ -36,6 +47,6 @@ public static String generateActivationKey() { * @return the generated reset key */ public static String generateResetKey() { - return RandomStringUtils.randomNumeric(DEF_COUNT); + return generateRandomAlphanumericString(); } }