mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-04-25 12:33:54 -04:00
Move random number generator to config
Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
parent
9e7efc1cf3
commit
ef31ee8a57
@ -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 val config = Config.captchaConfig
|
||||||
|
|
||||||
private def getNextRandomInt(max: Int): Int =
|
|
||||||
random.synchronized {
|
|
||||||
random.nextInt(max)
|
|
||||||
}
|
|
||||||
|
|
||||||
def getProviderById(id: String): ChallengeProvider = {
|
def getProviderById(id: String): ChallengeProvider = {
|
||||||
return providers(id)
|
return providers(id)
|
||||||
}
|
}
|
||||||
@ -58,7 +51,7 @@ object CaptchaProviders {
|
|||||||
def getProvider(param: Parameters): Option[ChallengeProvider] = {
|
def getProvider(param: Parameters): Option[ChallengeProvider] = {
|
||||||
val providerConfig = filterProviderByParam(param).toList
|
val providerConfig = filterProviderByParam(param).toList
|
||||||
if (providerConfig.length > 0) {
|
if (providerConfig.length > 0) {
|
||||||
val randomIndex = getNextRandomInt(providerConfig.length)
|
val randomIndex = Config.getNextRandomInt(providerConfig.length)
|
||||||
val providerIndex = providerConfig(randomIndex)._1
|
val providerIndex = providerConfig(randomIndex)._1
|
||||||
val selectedProvider = providers(providerIndex)
|
val selectedProvider = providers(providerIndex)
|
||||||
selectedProvider.configure(providerConfig(randomIndex)._2)
|
selectedProvider.configure(providerConfig(randomIndex)._2)
|
||||||
|
@ -49,6 +49,13 @@ object Config {
|
|||||||
val allowedMedia: Set[String] = captchaConfig.flatMap(_.allowedMedia).toSet
|
val allowedMedia: Set[String] = captchaConfig.flatMap(_.allowedMedia).toSet
|
||||||
val allowedInputType: Set[String] = captchaConfig.flatMap(_.allowedInputType).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 = {
|
private def getDefaultConfig(): String = {
|
||||||
val defaultConfigMap =
|
val defaultConfigMap =
|
||||||
(AttributesEnum.RANDOM_SEED.toString -> new ju.Random().nextInt()) ~
|
(AttributesEnum.RANDOM_SEED.toString -> new ju.Random().nextInt()) ~
|
||||||
|
Loading…
x
Reference in New Issue
Block a user