Class HashedCaptchaValidator
java.lang.Object
cloud.opencode.base.captcha.validator.HashedCaptchaValidator
- All Implemented Interfaces:
CaptchaValidator
Hashed Captcha Validator - Validator for HashedCaptchaStore
哈希验证码验证器 - 用于 HashedCaptchaStore 的验证器
This validator works with HashedCaptchaStore to verify plaintext answers
against stored hashes. It must be used instead of SimpleCaptchaValidator
when the store hashes answers.
此验证器与 HashedCaptchaStore 配合使用,验证明文答案与存储的哈希。
当存储对答案进行哈希时,必须使用此验证器替代 SimpleCaptchaValidator。
Features | 主要功能:
- Transparent hash verification - 透明哈希验证
- Atomic verify-and-remove (one-time validation) - 原子验证并删除(一次性验证)
- Timing-safe comparison via SHA-256 - 通过 SHA-256 的时间安全比较
Usage Examples | 使用示例:
HashedCaptchaStore store = HashedCaptchaStore.wrap(CaptchaStore.memory());
CaptchaValidator validator = new HashedCaptchaValidator(store);
ValidationResult result = validator.validate(id, answer);
Security | 安全性:
- Thread-safe: Yes (delegates to thread-safe store) - 线程安全: 是(委托给线程安全的存储)
- Null-safe: No (store, id, answer must not be null) - 空值安全: 否
- Since:
- JDK 25, opencode-base-captcha V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new validator with the specified hashed store. -
Method Summary
Modifier and TypeMethodDescriptionValidates a CAPTCHA answer against the stored hash.Validates a CAPTCHA answer against the stored hash.
-
Constructor Details
-
HashedCaptchaValidator
Creates a new validator with the specified hashed store. 使用指定的哈希存储创建新验证器。- Parameters:
store- the hashed CAPTCHA store | 哈希验证码存储
-
-
Method Details
-
validate
Validates a CAPTCHA answer against the stored hash. 验证验证码答案与存储的哈希。- Specified by:
validatein interfaceCaptchaValidator- Parameters:
id- the CAPTCHA ID | 验证码 IDanswer- the plaintext answer | 明文答案- Returns:
- the validation result | 验证结果
-
validate
Validates a CAPTCHA answer against the stored hash. 验证验证码答案与存储的哈希。The
caseSensitiveparameter is ignored because case sensitivity is configured at theHashedCaptchaStorelevel during construction.caseSensitive参数被忽略,因为大小写敏感性在HashedCaptchaStore构造时配置。- Specified by:
validatein interfaceCaptchaValidator- Parameters:
id- the CAPTCHA ID | 验证码 IDanswer- the plaintext answer | 明文答案caseSensitive- ignored (configured on store) | 忽略(在存储上配置)- Returns:
- the validation result | 验证结果
-