Class CaptchaChars

java.lang.Object
cloud.opencode.base.captcha.support.CaptchaChars

public final class CaptchaChars extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    static 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 Type
    Method
    Description
    static String
    generate(CaptchaType type, int length)
    Generates random characters for the specified type.
    static String[]
    Generates a random arithmetic expression.
    static String
    generateChinese(int length)
    Generates random Chinese characters.
    static String
    generateFromChars(char[] chars, int length)
    Generates random characters from the specified character set.
    static Random
    Gets the Random instance.
    static int
    randomInt(int bound)
    Generates a random integer within range.
    static int
    randomInt(int min, int max)
    Generates a random integer within range.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NUMERIC

      public static final char[] NUMERIC
      Numeric characters (0-9) | 数字字符
    • ALPHA_LOWER

      public static final char[] ALPHA_LOWER
      Alphabetic lowercase characters | 字母小写字符
    • ALPHA_UPPER

      public static final char[] ALPHA_UPPER
      Alphabetic uppercase characters | 字母大写字符
    • ALPHA

      public static final char[] ALPHA
      Alphabetic mixed case characters | 字母混合大小写字符
    • ALPHANUMERIC

      public static final char[] ALPHANUMERIC
      Alphanumeric characters (avoiding similar characters like 0/O, 1/l/I) | 字母数字字符(避免相似字符)
    • CHINESE

      public static final String[] CHINESE
      Common Chinese characters for CAPTCHA | 常用中文验证码字符
  • Method Details

    • generate

      public static String generate(CaptchaType type, int length)
      Generates random characters for the specified type. 为指定类型生成随机字符。
      Parameters:
      type - the CAPTCHA type | 验证码类型
      length - the number of characters | 字符数量
      Returns:
      the generated characters | 生成的字符
    • generateFromChars

      public static String generateFromChars(char[] chars, int length)
      Generates random characters from the specified character set. 从指定字符集生成随机字符。
      Parameters:
      chars - the character set | 字符集
      length - the number of characters | 字符数量
      Returns:
      the generated string | 生成的字符串
    • generateChinese

      public static String generateChinese(int length)
      Generates random Chinese characters. 生成随机中文字符。
      Parameters:
      length - the number of characters | 字符数量
      Returns:
      the generated string | 生成的字符串
    • generateArithmetic

      public static String[] generateArithmetic()
      Generates a random arithmetic expression. 生成随机算术表达式。
      Returns:
      an array containing [expression, answer] | 包含 [表达式, 答案] 的数组
    • getRandom

      public static Random 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 | 随机整数