Class VerifyCodeUtil

java.lang.Object
cloud.opencode.base.core.random.VerifyCodeUtil

public final class VerifyCodeUtil extends Object
Verification Code Utility - Generate secure verification codes 验证码工具类 - 生成安全验证码

Provides secure verification code generation using SecureRandom.

使用 SecureRandom 提供安全的验证码生成。

Features | 主要功能:

  • Numeric codes (6 digits default) - 数字验证码
  • Alphanumeric codes - 字母数字混合验证码
  • No-confusing codes (no 0, O, 1, I, L) - 无混淆字符验证码
  • Builder pattern for custom codes - 构建器模式自定义

Usage Examples | 使用示例:

String code = VerifyCodeUtil.numeric();       // 6-digit
String code = VerifyCodeUtil.numeric(4);      // 4-digit
String code = VerifyCodeUtil.noConfusing(6);  // no confusing chars

// Builder pattern - 构建器模式
String code = VerifyCodeUtil.builder()
    .length(8)
    .alphanumeric()
    .excludeConfusing()
    .build();

Security | 安全性:

  • Thread-safe: Yes (SecureRandom) - 线程安全: 是
  • Cryptographically secure - 加密安全

Performance | 性能特性:

  • Time complexity: O(n) where n = code length - O(n), n为验证码长度
  • Space complexity: O(n) for generated code - 生成的验证码 O(n)
Since:
JDK 25, opencode-base-core V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Verification code builder 验证码构建器
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    alphabetic(int length)
    Generates an alphabetic verification code 生成字母验证码
    static String
    alphanumeric(int length)
    Generates an alphanumeric verification code 生成字母数字混合验证码
    Gets the verification code builder 获取验证码构建器
    static String
    generate(int length, String chars)
    Generates a verification code with a custom character set 生成自定义字符集验证码
    static String
    noConfusing(int length)
    Generates a non-confusing verification code (excludes 0, O, 1, I, L, etc.)
    static String
    Generates a 6-digit numeric verification code 生成 6 位数字验证码
    static String
    numeric(int length)
    Generates a numeric verification code of specified length 生成指定长度数字验证码
    static String
    numericRange(int min, int max)
    Generates a numeric verification code within a range 生成范围内的数字验证码

    Methods inherited from class Object

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

    • numeric

      public static String numeric()
      Generates a 6-digit numeric verification code 生成 6 位数字验证码
    • numeric

      public static String numeric(int length)
      Generates a numeric verification code of specified length 生成指定长度数字验证码
    • alphabetic

      public static String alphabetic(int length)
      Generates an alphabetic verification code 生成字母验证码
    • alphanumeric

      public static String alphanumeric(int length)
      Generates an alphanumeric verification code 生成字母数字混合验证码
    • noConfusing

      public static String noConfusing(int length)
      Generates a non-confusing verification code (excludes 0, O, 1, I, L, etc.) 生成无混淆字符的验证码(排除 0, O, 1, I, L 等)
    • numericRange

      public static String numericRange(int min, int max)
      Generates a numeric verification code within a range 生成范围内的数字验证码
    • generate

      public static String generate(int length, String chars)
      Generates a verification code with a custom character set 生成自定义字符集验证码
    • builder

      public static VerifyCodeUtil.Builder builder()
      Gets the verification code builder 获取验证码构建器