From ef31ee8a5713ecf4f13b9956af2a59469c242711 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Tue, 20 Apr 2021 03:05:13 +0530 Subject: [PATCH 01/13] Move random number generator to config Signed-off-by: Rahul Rudragoudar --- src/main/scala/lc/core/captchaProviders.scala | 9 +-------- src/main/scala/lc/core/config.scala | 7 +++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/scala/lc/core/captchaProviders.scala b/src/main/scala/lc/core/captchaProviders.scala index eda74f0..453aafc 100644 --- a/src/main/scala/lc/core/captchaProviders.scala +++ b/src/main/scala/lc/core/captchaProviders.scala @@ -23,15 +23,8 @@ object CaptchaProviders { } } - private val seed = Config.seed - private val random = new scala.util.Random(seed) private val config = Config.captchaConfig - private def getNextRandomInt(max: Int): Int = - random.synchronized { - random.nextInt(max) - } - def getProviderById(id: String): ChallengeProvider = { return providers(id) } @@ -58,7 +51,7 @@ object CaptchaProviders { def getProvider(param: Parameters): Option[ChallengeProvider] = { val providerConfig = filterProviderByParam(param).toList if (providerConfig.length > 0) { - val randomIndex = getNextRandomInt(providerConfig.length) + val randomIndex = Config.getNextRandomInt(providerConfig.length) val providerIndex = providerConfig(randomIndex)._1 val selectedProvider = providers(providerIndex) selectedProvider.configure(providerConfig(randomIndex)._2) diff --git a/src/main/scala/lc/core/config.scala b/src/main/scala/lc/core/config.scala index 1ada43f..6e57a89 100644 --- a/src/main/scala/lc/core/config.scala +++ b/src/main/scala/lc/core/config.scala @@ -49,6 +49,13 @@ object Config { val allowedMedia: Set[String] = captchaConfig.flatMap(_.allowedMedia).toSet val allowedInputType: Set[String] = captchaConfig.flatMap(_.allowedInputType).toSet + private val random = new scala.util.Random(seed) + + def getNextRandomInt(max: Int): Int = + random.synchronized { + random.nextInt(max) + } + private def getDefaultConfig(): String = { val defaultConfigMap = (AttributesEnum.RANDOM_SEED.toString -> new ju.Random().nextInt()) ~ From 3682b2cb7dcf69f11622c0f271f5a5171f80a345 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Tue, 20 Apr 2021 03:06:47 +0530 Subject: [PATCH 02/13] Randomize captcha generation Signed-off-by: Rahul Rudragoudar --- src/main/scala/lc/background/taskThread.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/scala/lc/background/taskThread.scala b/src/main/scala/lc/background/taskThread.scala index 33ae997..2b5cd99 100644 --- a/src/main/scala/lc/background/taskThread.scala +++ b/src/main/scala/lc/background/taskThread.scala @@ -2,7 +2,7 @@ package lc.background import lc.database.Statements import java.util.concurrent.{ScheduledThreadPoolExecutor, TimeUnit} -import lc.core.Captcha +import lc.core.{Captcha, Config} import lc.core.{Parameters, Size} class BackgroundTask(throttle: Int, timeLimit: Int) { @@ -22,13 +22,21 @@ class BackgroundTask(throttle: Int, timeLimit: Int) { if (imageNum.next()) throttleIn = (throttleIn - imageNum.getInt("total")) while (0 < throttleIn) { - Captcha.generateChallenge(Parameters("medium", "image/png", "text", Option(Size(0, 0)))) + Captcha.generateChallenge(getRandomParam()) throttleIn -= 1 } } catch { case exception: Exception => println(exception) } } } + private def getRandomParam(): Parameters = { + val level = Config.allowedLevels.toList(Config.getNextRandomInt(Config.allowedLevels.size)) + val media = Config.allowedMedia.toList(Config.getNextRandomInt(Config.allowedMedia.size)) + val inputType = Config.allowedInputType.toList(Config.getNextRandomInt(Config.allowedInputType.size)) + + Parameters(level, media, inputType, Option(Size(0,0))) + } + def beginThread(delay: Int): Unit = { val ex = new ScheduledThreadPoolExecutor(1) ex.scheduleWithFixedDelay(task, 1, delay, TimeUnit.SECONDS) From 8ea0652331356ab7963b3611f8695391b7effb01 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Tue, 20 Apr 2021 03:07:35 +0530 Subject: [PATCH 03/13] Java formatter Signed-off-by: Rahul Rudragoudar --- .../lc/captchas/PoppingCharactersCaptcha.java | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/main/java/lc/captchas/PoppingCharactersCaptcha.java b/src/main/java/lc/captchas/PoppingCharactersCaptcha.java index 4ce15b4..fd5d0ca 100644 --- a/src/main/java/lc/captchas/PoppingCharactersCaptcha.java +++ b/src/main/java/lc/captchas/PoppingCharactersCaptcha.java @@ -36,16 +36,18 @@ public class PoppingCharactersCaptcha implements ChallengeProvider { advances.add(currX); currX += font.getStringBounds(String.valueOf(c), frc).getWidth(); currX += spacing; - }; + } + ; graphics2D.dispose(); - return advances.toArray(new Integer[]{}); + return advances.toArray(new Integer[] {}); } private BufferedImage makeImage(final Consumer f) { final var img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); final var graphics2D = img.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + graphics2D.setRenderingHint( + RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics2D.setFont(font); f.accept(graphics2D); graphics2D.dispose(); @@ -63,21 +65,32 @@ public class PoppingCharactersCaptcha implements ChallengeProvider { final var writer = new GifSequenceWriter(output, 1, 900, true); final var advances = computeOffsets(text); final var prevColor = Color.getHSBColor(0f, 0f, 0.1f); - IntStream.range(0, text.length()).forEach(i -> { - final var color = Color.getHSBColor(HelperFunctions.randomNumber(0, 100)/100.0f, 0.6f, 1.0f); - final var prevI = (i - 1 + text.length()) % text.length(); - final var nextImage = makeImage((g) -> { - g.setColor(prevColor); - g.drawString(String.valueOf(text.charAt(prevI)), advances[prevI] + jitter(), 45 + jitter()); - g.setColor(color); - g.drawString(String.valueOf(text.charAt(i)), advances[i] + jitter(), 45 + jitter()); - }); - try { - writer.writeToSequence(nextImage); - } catch (final IOException e) { - e.printStackTrace(); - } - }); + IntStream.range(0, text.length()) + .forEach( + i -> { + final var color = + Color.getHSBColor(HelperFunctions.randomNumber(0, 100) / 100.0f, 0.6f, 1.0f); + final var prevI = (i - 1 + text.length()) % text.length(); + final var nextImage = + makeImage( + (g) -> { + g.setColor(prevColor); + g.drawString( + String.valueOf(text.charAt(prevI)), + advances[prevI] + jitter(), + 45 + jitter()); + g.setColor(color); + g.drawString( + String.valueOf(text.charAt(i)), + advances[i] + jitter(), + 45 + jitter()); + }); + try { + writer.writeToSequence(nextImage); + } catch (final IOException e) { + e.printStackTrace(); + } + }); writer.close(); output.close(); return byteArrayOutputStream.toByteArray(); From 8f0f29c579087846784922959337e2a25c11b617 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Tue, 20 Apr 2021 13:53:08 +0530 Subject: [PATCH 04/13] Minor fix Signed-off-by: Rahul Rudragoudar --- src/main/scala/lc/background/taskThread.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/lc/background/taskThread.scala b/src/main/scala/lc/background/taskThread.scala index 2b5cd99..3508d02 100644 --- a/src/main/scala/lc/background/taskThread.scala +++ b/src/main/scala/lc/background/taskThread.scala @@ -34,7 +34,7 @@ class BackgroundTask(throttle: Int, timeLimit: Int) { val media = Config.allowedMedia.toList(Config.getNextRandomInt(Config.allowedMedia.size)) val inputType = Config.allowedInputType.toList(Config.getNextRandomInt(Config.allowedInputType.size)) - Parameters(level, media, inputType, Option(Size(0,0))) + Parameters(level, media, inputType, Some(Size(0,0))) } def beginThread(delay: Int): Unit = { From 241be1631c5049f5b7a1a535a1313ad75344f600 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Tue, 20 Apr 2021 13:53:08 +0530 Subject: [PATCH 05/13] Minor fix Signed-off-by: Rahul Rudragoudar --- src/main/scala/lc/background/taskThread.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/lc/background/taskThread.scala b/src/main/scala/lc/background/taskThread.scala index 2b5cd99..3508d02 100644 --- a/src/main/scala/lc/background/taskThread.scala +++ b/src/main/scala/lc/background/taskThread.scala @@ -34,7 +34,7 @@ class BackgroundTask(throttle: Int, timeLimit: Int) { val media = Config.allowedMedia.toList(Config.getNextRandomInt(Config.allowedMedia.size)) val inputType = Config.allowedInputType.toList(Config.getNextRandomInt(Config.allowedInputType.size)) - Parameters(level, media, inputType, Option(Size(0,0))) + Parameters(level, media, inputType, Some(Size(0,0))) } def beginThread(delay: Int): Unit = { From d3d5296ccd27950789b01eca4ab88eed55549d08 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Wed, 21 Apr 2021 14:27:19 +0530 Subject: [PATCH 06/13] Disable JavaFmt on compile Signed-off-by: Rahul Rudragoudar --- build.sbt | 1 + 1 file changed, 1 insertion(+) diff --git a/build.sbt b/build.sbt index 01eeee4..10e82b4 100644 --- a/build.sbt +++ b/build.sbt @@ -23,6 +23,7 @@ scalacOptions ++= List( ) javacOptions += "-g:none" compileOrder := CompileOrder.JavaThenScala +javafmtOnCompile := false assembly / mainClass := Some("lc.LCFramework") Compile / run / mainClass := Some("lc.LCFramework") assembly / assemblyJarName := "LibreCaptcha.jar" From 98c304ccd4d606b2bcc134379d8f3a3e47e81c29 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Wed, 21 Apr 2021 14:39:20 +0530 Subject: [PATCH 07/13] Pick a random captcha provider instead of params Signed-off-by: Rahul Rudragoudar --- src/main/scala/lc/background/taskThread.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/scala/lc/background/taskThread.scala b/src/main/scala/lc/background/taskThread.scala index 3508d02..6e9dbd8 100644 --- a/src/main/scala/lc/background/taskThread.scala +++ b/src/main/scala/lc/background/taskThread.scala @@ -30,11 +30,16 @@ class BackgroundTask(throttle: Int, timeLimit: Int) { } private def getRandomParam(): Parameters = { - val level = Config.allowedLevels.toList(Config.getNextRandomInt(Config.allowedLevels.size)) - val media = Config.allowedMedia.toList(Config.getNextRandomInt(Config.allowedMedia.size)) - val inputType = Config.allowedInputType.toList(Config.getNextRandomInt(Config.allowedInputType.size)) + val captcha = pickRandom(Config.captchaConfig) + val level = pickRandom(captcha.allowedLevels) + val media = pickRandom(captcha.allowedMedia) + val inputType = pickRandom(captcha.allowedInputType) - Parameters(level, media, inputType, Some(Size(0,0))) + Parameters(level, media, inputType, Some(Size(0, 0))) + } + + private def pickRandom[T](list: List[T]): T = { + list(Config.getNextRandomInt(list.size)) } def beginThread(delay: Int): Unit = { From e38c3b680aae4365f28242fc1bf9ba1501cd1ac0 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Wed, 21 Apr 2021 14:43:00 +0530 Subject: [PATCH 08/13] Reformat:Scalafmt Signed-off-by: Rahul Rudragoudar --- src/main/scala/lc/core/config.scala | 6 +- src/main/scala/lc/database/statements.scala | 2 +- src/main/scala/lc/server/Server.scala | 69 ++++++++++++--------- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/main/scala/lc/core/config.scala b/src/main/scala/lc/core/config.scala index 6e57a89..367104a 100644 --- a/src/main/scala/lc/core/config.scala +++ b/src/main/scala/lc/core/config.scala @@ -52,9 +52,9 @@ object Config { private val random = new scala.util.Random(seed) def getNextRandomInt(max: Int): Int = - random.synchronized { - random.nextInt(max) - } + random.synchronized { + random.nextInt(max) + } private def getDefaultConfig(): String = { val defaultConfigMap = diff --git a/src/main/scala/lc/database/statements.scala b/src/main/scala/lc/database/statements.scala index fdbd637..2d3d276 100644 --- a/src/main/scala/lc/database/statements.scala +++ b/src/main/scala/lc/database/statements.scala @@ -116,7 +116,7 @@ object Statements { org.h2.jdbc.JdbcSQLNonTransientException: General error: "java.lang.NullPointerException"; SQL statement: SELECT image FROM challenge c, mapId m WHERE c.token=m.token AND m.uuid = ? [50000-200] ``` - */ + */ private val dbConn: DBConn = new DBConn() private val maxAttempts = 10 val tlStmts: ThreadLocal[Statements] = ThreadLocal.withInitial(() => new Statements(dbConn, maxAttempts)) diff --git a/src/main/scala/lc/server/Server.scala b/src/main/scala/lc/server/Server.scala index efc3d33..ffb3d62 100644 --- a/src/main/scala/lc/server/Server.scala +++ b/src/main/scala/lc/server/Server.scala @@ -11,37 +11,50 @@ import scala.io.Source import org.limium.picoserve.Server.StringResponse class Server(port: Int) { - val server: picoserve.Server = picoserve.Server.builder() + val server: picoserve.Server = picoserve.Server + .builder() .port(port) .backlog(32) - .POST("/v1/captcha", (request) => { - val json = parse(request.getBodyString()) - val param = json.extract[Parameters] - val id = Captcha.getChallenge(param) - getResponse(id) - }) - .GET("/v1/media", (request) => { - val params = request.getQueryParams() - val result = if (params.containsKey("id")) { - val paramId = params.get("id").get(0) - val id = Id(paramId) - Captcha.getCaptcha(id) - } else { - Left(Error(ErrorMessageEnum.INVALID_PARAM.toString + "=> id")) + .POST( + "/v1/captcha", + (request) => { + val json = parse(request.getBodyString()) + val param = json.extract[Parameters] + val id = Captcha.getChallenge(param) + getResponse(id) } - getResponse(result) - }) - .POST("/v1/answer", (request) => { - val json = parse(request.getBodyString()) - val answer = json.extract[Answer] - val result = Captcha.checkAnswer(answer) - getResponse(result) - }) - .GET("/demo/index.html", (_) => { - val resStream = getClass().getResourceAsStream("/index.html") - val str = Source.fromInputStream(resStream).mkString - new StringResponse(200, str) - }) + ) + .GET( + "/v1/media", + (request) => { + val params = request.getQueryParams() + val result = if (params.containsKey("id")) { + val paramId = params.get("id").get(0) + val id = Id(paramId) + Captcha.getCaptcha(id) + } else { + Left(Error(ErrorMessageEnum.INVALID_PARAM.toString + "=> id")) + } + getResponse(result) + } + ) + .POST( + "/v1/answer", + (request) => { + val json = parse(request.getBodyString()) + val answer = json.extract[Answer] + val result = Captcha.checkAnswer(answer) + getResponse(result) + } + ) + .GET( + "/demo/index.html", + (_) => { + val resStream = getClass().getResourceAsStream("/index.html") + val str = Source.fromInputStream(resStream).mkString + new StringResponse(200, str) + } + ) .build() private def getResponse(response: Either[Error, ByteConvert]): ByteResponse = { From d62951fa5127e2cd106fe9560a435a8f7a57561e Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Wed, 21 Apr 2021 14:56:58 +0530 Subject: [PATCH 09/13] Minor fix Signed-off-by: Rahul Rudragoudar --- src/main/scala/lc/background/taskThread.scala | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/scala/lc/background/taskThread.scala b/src/main/scala/lc/background/taskThread.scala index a00a4d5..6e9dbd8 100644 --- a/src/main/scala/lc/background/taskThread.scala +++ b/src/main/scala/lc/background/taskThread.scala @@ -35,15 +35,11 @@ class BackgroundTask(throttle: Int, timeLimit: Int) { val media = pickRandom(captcha.allowedMedia) val inputType = pickRandom(captcha.allowedInputType) -<<<<<<< HEAD Parameters(level, media, inputType, Some(Size(0, 0))) } private def pickRandom[T](list: List[T]): T = { list(Config.getNextRandomInt(list.size)) -======= - Parameters(level, media, inputType, Some(Size(0,0))) ->>>>>>> 8f0f29c579087846784922959337e2a25c11b617 } def beginThread(delay: Int): Unit = { From 0d33f51f9e0a509dc8530d2a2ecb81333b35b067 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Sat, 24 Apr 2021 19:36:48 +0530 Subject: [PATCH 10/13] Move random number generator to HelperFunctions Signed-off-by: Rahul Rudragoudar --- src/main/java/lc/misc/HelperFunctions.java | 16 +++++++++++++--- src/main/scala/lc/core/config.scala | 8 ++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/lc/misc/HelperFunctions.java b/src/main/java/lc/misc/HelperFunctions.java index bda31b8..bb7c868 100644 --- a/src/main/java/lc/misc/HelperFunctions.java +++ b/src/main/java/lc/misc/HelperFunctions.java @@ -1,9 +1,14 @@ package lc.misc; import java.awt.*; +import java.util.Random; public class HelperFunctions { + public static int seed; + + private static Random random = new Random(seed); + public static void setRenderingHints(Graphics2D g2d) { g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); @@ -25,13 +30,18 @@ public class HelperFunctions { public static String randomString(final int n, final String characters) { final StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < n; i++) { - int index = (int) (characters.length() * Math.random()); + int index = randomNumber(characters.length()); stringBuilder.append(characters.charAt(index)); } return stringBuilder.toString(); } - public static int randomNumber(int min, int max) { - return (int) (Math.random() * ((max - min) + 1)) + min; + synchronized public static int randomNumber(int min, int max) { + return (random.nextInt() * ((max - min) + 1)) + min; } + + synchronized public static int randomNumber(int bound) { + return random.nextInt(bound); + } + } diff --git a/src/main/scala/lc/core/config.scala b/src/main/scala/lc/core/config.scala index 367104a..fb08994 100644 --- a/src/main/scala/lc/core/config.scala +++ b/src/main/scala/lc/core/config.scala @@ -6,6 +6,7 @@ import org.json4s.jackson.JsonMethods.{parse, render, pretty} import org.json4s.JsonDSL._ import java.io.{FileNotFoundException, File, PrintWriter} import java.{util => ju} +import lc.misc.HelperFunctions object Config { @@ -49,12 +50,7 @@ object Config { val allowedMedia: Set[String] = captchaConfig.flatMap(_.allowedMedia).toSet val allowedInputType: Set[String] = captchaConfig.flatMap(_.allowedInputType).toSet - private val random = new scala.util.Random(seed) - - def getNextRandomInt(max: Int): Int = - random.synchronized { - random.nextInt(max) - } + HelperFunctions.seed = seed private def getDefaultConfig(): String = { val defaultConfigMap = From 30bb26473e507a714e54c4c8c23df9c11930f8c0 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Sat, 24 Apr 2021 19:37:44 +0530 Subject: [PATCH 11/13] Update random generator reference Signed-off-by: Rahul Rudragoudar --- src/main/scala/lc/background/taskThread.scala | 3 ++- src/main/scala/lc/core/captchaProviders.scala | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/scala/lc/background/taskThread.scala b/src/main/scala/lc/background/taskThread.scala index 6e9dbd8..8278469 100644 --- a/src/main/scala/lc/background/taskThread.scala +++ b/src/main/scala/lc/background/taskThread.scala @@ -4,6 +4,7 @@ import lc.database.Statements import java.util.concurrent.{ScheduledThreadPoolExecutor, TimeUnit} import lc.core.{Captcha, Config} import lc.core.{Parameters, Size} +import lc.misc.HelperFunctions class BackgroundTask(throttle: Int, timeLimit: Int) { @@ -39,7 +40,7 @@ class BackgroundTask(throttle: Int, timeLimit: Int) { } private def pickRandom[T](list: List[T]): T = { - list(Config.getNextRandomInt(list.size)) + list(HelperFunctions.randomNumber(list.size)) } def beginThread(delay: Int): Unit = { diff --git a/src/main/scala/lc/core/captchaProviders.scala b/src/main/scala/lc/core/captchaProviders.scala index 453aafc..f778037 100644 --- a/src/main/scala/lc/core/captchaProviders.scala +++ b/src/main/scala/lc/core/captchaProviders.scala @@ -4,6 +4,7 @@ import lc.captchas._ import lc.captchas.interfaces.ChallengeProvider import lc.captchas.interfaces.Challenge import scala.collection.mutable.Map +import lc.misc.HelperFunctions object CaptchaProviders { private val providers = Map( @@ -51,7 +52,7 @@ object CaptchaProviders { def getProvider(param: Parameters): Option[ChallengeProvider] = { val providerConfig = filterProviderByParam(param).toList if (providerConfig.length > 0) { - val randomIndex = Config.getNextRandomInt(providerConfig.length) + val randomIndex = HelperFunctions.randomNumber(providerConfig.length) val providerIndex = providerConfig(randomIndex)._1 val selectedProvider = providers(providerIndex) selectedProvider.configure(providerConfig(randomIndex)._2) From 04755c0a07de4fd135c2e612210273f1f8dd11a7 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Sat, 24 Apr 2021 20:44:20 +0530 Subject: [PATCH 12/13] Add method to set seed Signed-off-by: Rahul Rudragoudar --- src/main/java/lc/misc/HelperFunctions.java | 4 ++++ src/main/scala/lc/core/config.scala | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/lc/misc/HelperFunctions.java b/src/main/java/lc/misc/HelperFunctions.java index bb7c868..2b37fc0 100644 --- a/src/main/java/lc/misc/HelperFunctions.java +++ b/src/main/java/lc/misc/HelperFunctions.java @@ -9,6 +9,10 @@ public class HelperFunctions { private static Random random = new Random(seed); + synchronized public static void setSeed(long seed){ + random.setSeed(seed); + } + public static void setRenderingHints(Graphics2D g2d) { g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); diff --git a/src/main/scala/lc/core/config.scala b/src/main/scala/lc/core/config.scala index fb08994..f2da049 100644 --- a/src/main/scala/lc/core/config.scala +++ b/src/main/scala/lc/core/config.scala @@ -50,7 +50,7 @@ object Config { val allowedMedia: Set[String] = captchaConfig.flatMap(_.allowedMedia).toSet val allowedInputType: Set[String] = captchaConfig.flatMap(_.allowedInputType).toSet - HelperFunctions.seed = seed + HelperFunctions.setSeed(seed) private def getDefaultConfig(): String = { val defaultConfigMap = From 17083475048c965b94dc139a9c2664c718322fed Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Sat, 24 Apr 2021 20:53:28 +0530 Subject: [PATCH 13/13] Remove seed member var Signed-off-by: Rahul Rudragoudar --- src/main/java/lc/misc/HelperFunctions.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/lc/misc/HelperFunctions.java b/src/main/java/lc/misc/HelperFunctions.java index 2b37fc0..47e8614 100644 --- a/src/main/java/lc/misc/HelperFunctions.java +++ b/src/main/java/lc/misc/HelperFunctions.java @@ -5,9 +5,7 @@ import java.util.Random; public class HelperFunctions { - public static int seed; - - private static Random random = new Random(seed); + private static Random random = new Random(); synchronized public static void setSeed(long seed){ random.setSeed(seed);