Class TimeBasedCaptchaValidator
java.lang.Object
cloud.opencode.base.captcha.validator.TimeBasedCaptchaValidator
- All Implemented Interfaces:
CaptchaValidator
Time-Based Captcha Validator - Validation with timing checks
基于时间的验证码验证器 - 带时间检查的验证
This validator checks for suspiciously fast responses that might indicate automated attacks.
此验证器检查可能表示自动攻击的可疑快速响应。
Features | 主要功能:
- Minimum response time enforcement - 最小响应时间强制
- Expiration time check - 过期时间检查
- Suspicious timing detection - 可疑时间检测
Usage Examples | 使用示例:
TimeBasedCaptchaValidator validator = new TimeBasedCaptchaValidator(store);
validator.recordCreation(captchaId);
ValidationResult result = validator.validate(captchaId, answer);
Security | 安全性:
- Thread-safe: Yes (uses ConcurrentHashMap) - 线程安全: 是(使用ConcurrentHashMap)
- Null-safe: No (store, id, and answer must not be null) - 空值安全: 否(存储、ID和答案不能为null)
- Since:
- JDK 25, opencode-base-captcha V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new validator with the specified store. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears old creation time records.voidrecordCreation(String id) Records CAPTCHA creation time.Validates a CAPTCHA answer.Validates a CAPTCHA answer with case sensitivity option.
-
Constructor Details
-
TimeBasedCaptchaValidator
Creates a new validator with the specified store. 使用指定存储创建新验证器。- Parameters:
store- the CAPTCHA store | 验证码存储
-
-
Method Details
-
recordCreation
Records CAPTCHA creation time. 记录验证码创建时间。- Parameters:
id- the CAPTCHA ID | 验证码 ID
-
validate
Description copied from interface:CaptchaValidatorValidates a CAPTCHA answer. 验证验证码答案。- Specified by:
validatein interfaceCaptchaValidator- Parameters:
id- the CAPTCHA ID | 验证码 IDanswer- the provided answer | 提供的答案- Returns:
- the validation result | 验证结果
-
validate
Description copied from interface:CaptchaValidatorValidates a CAPTCHA answer with case sensitivity option. 验证验证码答案(带大小写敏感选项)。- Specified by:
validatein interfaceCaptchaValidator- Parameters:
id- the CAPTCHA ID | 验证码 IDanswer- the provided answer | 提供的答案caseSensitive- whether case sensitive | 是否区分大小写- Returns:
- the validation result | 验证结果
-
clearOldRecords
public void clearOldRecords()Clears old creation time records. 清除旧的创建时间记录。
-