This commit is contained in:
MaxKey
2022-04-22 22:00:39 +08:00
parent e31a83b679
commit b6d30a8730
8 changed files with 70 additions and 11 deletions

View File

@@ -0,0 +1,27 @@
package com.google.code.kaptcha.impl;
import java.util.Random;
import com.google.code.kaptcha.text.TextProducer;
import com.google.code.kaptcha.util.Configurable;
public class UniqueTextCreator extends Configurable implements TextProducer{
@Override
public String getText() {
int length = getConfig().getTextProducerCharLength();
char[] chars = getConfig().getTextProducerCharString();
Random rand = new Random();
StringBuffer text = new StringBuffer();
int i = 0;
while ( i < length){
char word= chars[rand.nextInt(chars.length)];
if(text.indexOf(word + "") <= -1 ) {
text.append(word);
i++;
}
}
return text.toString();
}
}