Skip to content

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

Notifications You must be signed in to change notification settings

guillaC/CaptchaNoJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>

Releases

No releases published

Packages

No packages published

Languages