From d797acdcac2dd2befa47a8ac2e0024e996959dd9 Mon Sep 17 00:00:00 2001 From: hrj Date: Sat, 2 Apr 2022 23:07:38 +0530 Subject: [PATCH] FilterChallenge: adjust difficult based on parameter --- src/main/scala/lc/captchas/FilterChallenge.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/scala/lc/captchas/FilterChallenge.scala b/src/main/scala/lc/captchas/FilterChallenge.scala index f846dbb..8178433 100644 --- a/src/main/scala/lc/captchas/FilterChallenge.scala +++ b/src/main/scala/lc/captchas/FilterChallenge.scala @@ -31,11 +31,12 @@ class FilterChallenge extends ChallengeProvider { } def returnChallenge(level: String, size: String): Challenge = { + val mediumLevel = level == "medium" val filterTypes = List(new FilterType1, new FilterType2) val r = new scala.util.Random - val alphabet = "abcdefghijklmnopqrstuvwxyz" - val n = 8 - val secret = LazyList.continually(r.nextInt(alphabet.size)).map(alphabet).take(n).mkString + val characters = if (mediumLevel) HelperFunctions.safeAlphaNum else HelperFunctions.safeCharacters + val n = if (mediumLevel) 5 else 7 + val secret = LazyList.continually(r.nextInt(characters.size)).map(characters).take(n).mkString val size2D = HelperFunctions.parseSize2D(size) val width = size2D(0) val height = size2D(1)