mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-13 06:53:19 -05:00
Randomize captcha generation
Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
parent
ef31ee8a57
commit
3682b2cb7d
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user