Skip to content

Commit

Permalink
添加是否区分大小写的配置
Browse files Browse the repository at this point in the history
  • Loading branch information
1992w committed Jul 5, 2020
1 parent ccf0568 commit 2517c4a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/SimpleCaptcha/Captcha.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public CaptchaInfo Generate(string captchaId)
public bool Validate(string captchaId, string code)
{
var val = _storage.Get(captchaId);
var result = !string.IsNullOrWhiteSpace(val) && val == code;
var comparisonType = _options.CurrentValue.IgnoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture;
var result = string.Equals(val, code, comparisonType);
if (result)
{
_storage.Remove(captchaId);
Expand Down
2 changes: 2 additions & 0 deletions src/SimpleCaptcha/CaptchaOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public class CaptchaOptions
public int ImageHeight { get; set; } = 36;

public TimeSpan ExpiryTime { get; set; } = TimeSpan.FromMinutes(5);

public bool IgnoreCase { get; set; } = true;
}
}

0 comments on commit 2517c4a

Please sign in to comment.