guillaC / CaptchaNoJS

Captcha DLL for ASP.NET (core, mvc, ..)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CaptchaNoJS

CaptchaNoJS protects ASP.NET/Core forms from spam, it's a self-hosted .NET library: no 3rd-party servers are involved in the generation, displaying, and validation of Captcha challenges.

Captcha.CaptchaType.Line

download

Captcha.CaptchaType.Circle

download

Usage example

Controller :
// GET: Example/Create
public IActionResult Create()
{
    Captcha captcha = new Captcha(200, 80, 6);
    ViewData["b64"] = captcha.GenerateAsB64(); // or captcha.GenerateAsB64(Captcha.CaptchaType.Circle);
    HttpContext.Session.SetString("captchaAnswer", captcha.GetAnswer());
    return View();
}
// POST: Example/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(String captcha)
{
    if (captcha == HttpContext.Session.GetString("captchaAnswer")) {
  ....
    }
}
View :
<form asp-action="Create">
    <div class="form-group">
        <label for="Captcha"> Captcha </label>
        <img src='data:image/Png;base64,@ViewData["b64"]' />
        <input type="text" class="form-control" name="captcha" />
   </div>
   <div class="form-group">
        <input type="submit" value="Save" class="btn btn-primary" />
   </div>
</form>

About

Captcha DLL for ASP.NET (core, mvc, ..)


Languages

Language:C# 100.0%