debug catpcha: only use alphabets

Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
hrj 2021-04-13 12:36:30 +05:30
parent 332bb2113b
commit 954399042c
2 changed files with 12 additions and 4 deletions

View File

@ -11,9 +11,17 @@ public class HelperFunctions {
RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
}
public static String randomString(int n) {
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz23456789$#%@&?";
StringBuilder stringBuilder = new StringBuilder();
public static final String alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public static final String numbers = "23456789";
public static final String specialCharacters = "$#%@&?";
public static final String allCharacters = alphabets + numbers + specialCharacters;
public static String randomString(final int n) {
return randomString(n, allCharacters);
}
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());
stringBuilder.append(characters.charAt(index));

View File

@ -58,7 +58,7 @@ class DebugCaptcha extends ChallengeProvider {
}
def returnChallenge(): Challenge = {
val secret = HelperFunctions.randomString(6)
val secret = HelperFunctions.randomString(6, HelperFunctions.alphabets)
new Challenge(simpleText(secret), "image/png", secret.toLowerCase())
}
}