java.lang.Object
org.miaixz.bus.extra.captcha.strategy.AbstractStrategy
org.miaixz.bus.extra.captcha.strategy.RandomStrategy
- All Implemented Interfaces:
Serializable,CodeStrategy
Random character CAPTCHA generation strategy. Generates a random CAPTCHA string from a given base character set and
length.
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Field Summary
Fields inherited from class org.miaixz.bus.extra.captcha.strategy.AbstractStrategy
baseStr, length -
Constructor Summary
ConstructorsConstructorDescriptionRandomStrategy(int count) Constructs a newRandomStrategyusing letters and numbers as the base character set.RandomStrategy(String baseStr, int length) Constructs a newRandomStrategywith a custom base character set and length. -
Method Summary
Methods inherited from class org.miaixz.bus.extra.captcha.strategy.AbstractStrategy
getLength
-
Constructor Details
-
RandomStrategy
public RandomStrategy(int count) Constructs a newRandomStrategyusing letters and numbers as the base character set.- Parameters:
count- The length of the CAPTCHA code to generate.
-
RandomStrategy
Constructs a newRandomStrategywith a custom base character set and length.- Parameters:
baseStr- The base character set from which to randomly select characters.length- The length of the CAPTCHA code to generate.
-
-
Method Details
-
generate
Description copied from interface:CodeStrategyGenerates the CAPTCHA code.- Returns:
- The CAPTCHA code.
-
verify
Description copied from interface:CodeStrategyVerifies if the user's input string matches the generated CAPTCHA code. Users can define their own matching logic by implementing this method.- Parameters:
code- The randomly generated CAPTCHA code.userInputCode- The CAPTCHA code entered by the user.- Returns:
- Whether the verification is successful.
-