diff --git a/Lazy.Captcha.Core/DefaultCaptcha.cs b/Lazy.Captcha.Core/DefaultCaptcha.cs
index 98ad2750b5d7d527231e3a1bfb019bb746f3d45b..4c2e16f84fe160e3f4e09d5d0bb5cf78f02c2e94 100644
--- a/Lazy.Captcha.Core/DefaultCaptcha.cs
+++ b/Lazy.Captcha.Core/DefaultCaptcha.cs
@@ -56,8 +56,9 @@ namespace Lazy.Captcha.Core
/// 验证码id
/// 用户输入的验证码
/// 校验成功时是否移除缓存(用于多次验证)
+ /// 校验失败时是否移除缓存
///
- public virtual bool Validate(string captchaId, string code, bool removeIfSuccess = true)
+ public virtual bool Validate(string captchaId, string code, bool removeIfSuccess = true,bool removeIfFail = true)
{
var val = _storage.Get(captchaId);
var comparisonType = _options.IgnoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture;
@@ -65,7 +66,7 @@ namespace Lazy.Captcha.Core
!string.IsNullOrWhiteSpace(val) &&
string.Equals(val, code, comparisonType);
- if (!success || (success && removeIfSuccess))
+ if ((!success && removeIfFail) || (success && removeIfSuccess))
{
_storage.Remove(captchaId);
}
diff --git a/Lazy.Captcha.Core/ICaptcha.cs b/Lazy.Captcha.Core/ICaptcha.cs
index 54ace6409d6b7292dedb200ba677f6a332690e4c..d37a808ddd1ae736b105da17022f08dea7e2538a 100644
--- a/Lazy.Captcha.Core/ICaptcha.cs
+++ b/Lazy.Captcha.Core/ICaptcha.cs
@@ -22,7 +22,8 @@ namespace Lazy.Captcha.Core
/// 楠岃瘉鐮乮d
/// 鐢ㄦ埛杈撳叆鐨勯獙璇佺爜
/// 鏍¢獙鎴愬姛鏃舵槸鍚︾Щ闄ょ紦瀛(鐢ㄤ簬澶氭楠岃瘉)
+ /// 鏍¢獙澶辫触鏃舵槸鍚︾Щ闄
///
- bool Validate(string captchaId, string code, bool removeIfSuccess = true);
+ bool Validate(string captchaId, string code, bool removeIfSuccess = true, bool removeIfFail = true);
}
}