v0.0.1 alpha
This commit is contained in:
commit
0631f17bf5
87 files changed
+3226
No files matched your search
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 CaptchaKit Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,44 @@
|
||||
# CaptchaKit
|
||||
|
||||
CaptchaKit is an ASP.NET Core CAPTCHA foundation with server-side, one-time validation and pluggable generators and storage.
|
||||
|
||||
`CaptchaKit.Core` has provider-neutral contracts. `CaptchaKit.AspNetCore` supplies a SkiaSharp text-image generator and `IDistributedCache` storage.
|
||||
|
||||
The package does not claim that image CAPTCHA alone defeats determined automation. Deploy it with rate limits, account lockout, and appropriate risk controls.
|
||||
|
||||
## Quick start
|
||||
|
||||
Install both packages at the same version:
|
||||
|
||||
```text
|
||||
dotnet add package CaptchaKit.AspNetCore --prerelease
|
||||
```
|
||||
|
||||
Configure a distributed cache (Redis is recommended for more than one application instance), then add the service:
|
||||
|
||||
```csharp
|
||||
builder.Services.AddStackExchangeRedisCache(options =>
|
||||
options.Configuration = builder.Configuration.GetConnectionString("Redis"));
|
||||
builder.Services.AddCaptchaKit(options =>
|
||||
{
|
||||
options.CodeLength = 5;
|
||||
options.Lifetime = TimeSpan.FromMinutes(2);
|
||||
options.CacheKeyPrefix = "myapp:captcha:";
|
||||
});
|
||||
```
|
||||
|
||||
An endpoint can obtain an image challenge and return it in the format used by its UI:
|
||||
|
||||
```csharp
|
||||
var challenge = await captcha.CreateAsync(cancellationToken);
|
||||
var imageData = $"data:{challenge.ContentType};base64,{Convert.ToBase64String(challenge.ImageBytes)}";
|
||||
```
|
||||
|
||||
Before completing the protected action, validate it once:
|
||||
|
||||
```csharp
|
||||
if (!await captcha.VerifyAsync(request.CaptchaId, request.CaptchaCode, cancellationToken))
|
||||
return Results.Unauthorized();
|
||||
```
|
||||
|
||||
`VerifyAsync` consumes the challenge on every attempt. Applications can replace `ICaptchaGenerator` or `ICaptchaChallengeStore` to use another challenge type or persistence backend.
|
||||
Binary file not shown.
Loaded 3 of 87 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user