
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Sam.ReCaptcha
is a robust package for implementing CAPTCHA in ASP.NET Core applications. It supports various CAPTCHA techniques, including text-based and math-based CAPTCHAs, helping to prevent automated attacks and enhance application security.
To add Sam.ReCaptcha
to your project, run the following command:
dotnet add package Sam.ReCaptcha
Program.cs
First, configure Sam.ReCaptcha
in Program.cs
:
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
var builder = WebApplication.CreateBuilder(args);
// Add required services
builder.Services.AddControllers();
builder.Services.AddSwaggerGen();
builder.Services.AddDistributedMemoryCache();
// CAPTCHA Configuration
var captchaOptions = new CaptchaOptions
{
CaptchaVariant = CaptchaTypes.DefaultCaptcha,
MathCaptchaOptions = new MathCaptchaOptions
{
MinValue = 10,
MaxValue = 20,
},
TextCaptchaOptions = new TextCaptchaOptions()
{
AllowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
CodeLength = 5,
CaseSensitivityMode = StringComparison.OrdinalIgnoreCase,
},
Font = ReCaptchaFonts.Timetwist,
ExpirationTimeInMinutes = 5,
ImageOptions = new CaptchaImageOptions
{
MinFontSize = 30,
MaxFontSize = 36,
TextColor = Color.Black,
ShadowColor = Color.Gray,
LetterSpacing = 30,
ShadowPositionOffset = new PointF(2, 2),
Rotation = new RotationOptions
{
MinRotation = -10,
MaxRotation = 10
}
},
LineDistortion = new LineDistortionOptions
{
LineColor = Color.Gray,
LineCount = 8
},
NoiseEffect = new NoiseEffectOptions
{
NoiseDensity = 200,
NoiseColor = Color.Silver
},
GradientBackground = new GradientBackgroundOptions
{
GradientStops =
[
new ColorStop(0, Color.LightBlue),
new ColorStop(0.5f, Color.White),
new ColorStop(1, Color.LightGray)
]
}
};
// Register CAPTCHA service
builder.Services.AddCaptcha(captchaOptions);
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
In CaptchaController.cs
, add the following endpoints for generating and validating CAPTCHAs:
using Microsoft.AspNetCore.Mvc;
using Sam.ReCaptcha.Services;
namespace Sam.ReCaptcha.WebApi.Controllers;
[ApiController]
[Route("[controller]/[action]")]
public class CaptchaController(ICaptchaService captchaService) : ControllerBase
{
[HttpGet("{id:guid}")]
public async Task<FileContentResult> ReCaptcha(Guid id)
{
var bytes = await captchaService.GenerateCaptchaImageAsync(id);
return File(bytes, "image/jpeg");
}
[HttpGet("{id:guid}")]
public async Task<bool> Validate(Guid id, [FromQuery] string code)
{
return await captchaService.Validate(id, code);
}
}
You can retrieve the CAPTCHA image in your frontend using a GET
request:
<img id="captchaImage" src="https://your-api-url.com/Captcha/ReCaptcha/{id}" />
To verify the entered code, send a GET
request:
GET https://your-api-url.com/Captcha/Validate/{id}?code=12345
Sam.ReCaptcha
is a powerful and flexible solution for adding CAPTCHA to ASP.NET Core applications. With extensive configuration options, visual effects, and security enhancements, this package provides an efficient way to prevent automated attacks and ensure the security of your application. 🚀
FAQs
Package Description
We found that sam.recaptcha demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.