Class CaptchaChars
java.lang.Object
cloud.opencode.base.captcha.support.CaptchaChars
Captcha Characters - Character generation utilities
验证码字符 - 字符生成工具
This class provides character sets and generation utilities for CAPTCHA.
此类提供验证码的字符集和生成工具。
Features | 主要功能:
- Multiple character set support (numeric, alpha, alphanumeric, Chinese) - 多种字符集支持
- Arithmetic expression generation - 算术表达式生成
- SecureRandom-based generation - 基于SecureRandom的生成
Usage Examples | 使用示例:
String code = CaptchaChars.generate(CaptchaType.ALPHANUMERIC, 4);
String chinese = CaptchaChars.generateChinese(4);
String[] arithmetic = CaptchaChars.generateArithmetic();
Security | 安全性:
- Thread-safe: Yes (uses SecureRandom) - 线程安全: 是(使用SecureRandom)
- Null-safe: No (type must not be null) - 空值安全: 否(类型不能为null)
- Since:
- JDK 25, opencode-base-captcha V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char[]Alphabetic mixed case characters | 字母混合大小写字符static final char[]Alphabetic lowercase characters | 字母小写字符static final char[]Alphabetic uppercase characters | 字母大写字符static final char[]Alphanumeric characters (avoiding similar characters like 0/O, 1/l/I) | 字母数字字符(避免相似字符)static final String[]Common Chinese characters for CAPTCHA | 常用中文验证码字符static final char[]Numeric characters (0-9) | 数字字符 -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringgenerate(CaptchaType type, int length) Generates random characters for the specified type.static String[]Generates a random arithmetic expression.static StringgenerateChinese(int length) Generates random Chinese characters.static StringgenerateFromChars(char[] chars, int length) Generates random characters from the specified character set.static RandomGets the Random instance.static intrandomInt(int bound) Generates a random integer within range.static intrandomInt(int min, int max) Generates a random integer within range.
-
Field Details
-
NUMERIC
public static final char[] NUMERICNumeric characters (0-9) | 数字字符 -
ALPHA_LOWER
public static final char[] ALPHA_LOWERAlphabetic lowercase characters | 字母小写字符 -
ALPHA_UPPER
public static final char[] ALPHA_UPPERAlphabetic uppercase characters | 字母大写字符 -
ALPHA
public static final char[] ALPHAAlphabetic mixed case characters | 字母混合大小写字符 -
ALPHANUMERIC
public static final char[] ALPHANUMERICAlphanumeric characters (avoiding similar characters like 0/O, 1/l/I) | 字母数字字符(避免相似字符) -
CHINESE
Common Chinese characters for CAPTCHA | 常用中文验证码字符
-
-
Method Details
-
generate
Generates random characters for the specified type. 为指定类型生成随机字符。- Parameters:
type- the CAPTCHA type | 验证码类型length- the number of characters | 字符数量- Returns:
- the generated characters | 生成的字符
-
generateFromChars
Generates random characters from the specified character set. 从指定字符集生成随机字符。- Parameters:
chars- the character set | 字符集length- the number of characters | 字符数量- Returns:
- the generated string | 生成的字符串
-
generateChinese
Generates random Chinese characters. 生成随机中文字符。- Parameters:
length- the number of characters | 字符数量- Returns:
- the generated string | 生成的字符串
-
generateArithmetic
Generates a random arithmetic expression. 生成随机算术表达式。- Returns:
- an array containing [expression, answer] | 包含 [表达式, 答案] 的数组
-
getRandom
Gets the Random instance. 获取 Random 实例。- Returns:
- the Random | Random 实例
-
randomInt
public static int randomInt(int bound) Generates a random integer within range. 在范围内生成随机整数。- Parameters:
bound- the upper bound (exclusive) | 上限(不包含)- Returns:
- the random integer | 随机整数
-
randomInt
public static int randomInt(int min, int max) Generates a random integer within range. 在范围内生成随机整数。- Parameters:
min- the minimum (inclusive) | 最小值(包含)max- the maximum (exclusive) | 最大值(不包含)- Returns:
- the random integer | 随机整数
-