Class VerifyCodeUtil
java.lang.Object
cloud.opencode.base.core.random.VerifyCodeUtil
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 ClassesModifier and TypeClassDescriptionstatic classVerification code builder 验证码构建器 -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringalphabetic(int length) Generates an alphabetic verification code 生成字母验证码static Stringalphanumeric(int length) Generates an alphanumeric verification code 生成字母数字混合验证码static VerifyCodeUtil.Builderbuilder()Gets the verification code builder 获取验证码构建器static StringGenerates a verification code with a custom character set 生成自定义字符集验证码static StringnoConfusing(int length) Generates a non-confusing verification code (excludes 0, O, 1, I, L, etc.)static Stringnumeric()Generates a 6-digit numeric verification code 生成 6 位数字验证码static Stringnumeric(int length) Generates a numeric verification code of specified length 生成指定长度数字验证码static StringnumericRange(int min, int max) Generates a numeric verification code within a range 生成范围内的数字验证码
-
Method Details
-
numeric
Generates a 6-digit numeric verification code 生成 6 位数字验证码 -
numeric
Generates a numeric verification code of specified length 生成指定长度数字验证码 -
alphabetic
Generates an alphabetic verification code 生成字母验证码 -
alphanumeric
Generates an alphanumeric verification code 生成字母数字混合验证码 -
noConfusing
Generates a non-confusing verification code (excludes 0, O, 1, I, L, etc.) 生成无混淆字符的验证码(排除 0, O, 1, I, L 等) -
numericRange
Generates a numeric verification code within a range 生成范围内的数字验证码 -
generate
-
builder
Gets the verification code builder 获取验证码构建器
-