Skip to content

An efficient and secured alternative of Google reCAPTCHA for .NET Core

Notifications You must be signed in to change notification settings

FarokhCode/Easy-Captcha

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Easy Captcha

An efficient and secured alternative of Google reCAPTCHA for ASP.NET Core and ASP.NET MVC which has been written with C#. If you are being tired of struggling with Google reCAPTCHA and also worried about performance and banning issue with it, just take a minute to go through it for your consideration. I am certain that you won't be regret.

c1 c2 c3 c4 c5 c6 c7 c8 c9 c10

How to use

  • Install it from Nuget:

    Install-Package EasyCaptchaCore -Version 1.0.0
    
  • Add ICaptchaService to your Statrup like this:

    services.AddTransient<ICaptchaService, CaptchaService>();
  • Enable Session in Configure method like this:

    app.UseSession();
  • Enable session IdleTimeout in your ConfigureServices If you are using .NET Core or MVC. You can change the session timeout if you want. It uses to store the Captcha in the user session securely.

    services.AddSession(options =>
              {
                  options.IdleTimeout = TimeSpan.FromMinutes(10);
              });
  • Use the code below in your View Layout:

    <img src="~/Captcha" alt="Captcha" />
  • In order to randomly change the Captcha text by clicking on it, you can use the code below:

    <img src="~/Captcha" alt="Captcha" style="cursor: pointer;" onclick="refreshImage(this);" />
    <script type="text/javascript">
              refreshImage = function (img) {
                  var source = img.src;
                  img.src = '';
    
                  source = source.split('?')[0];
                  source = source + '?' + new Date().getTime();
    
                  img.src = source;
              }
    </script>
  • Use the code below to compare the real Captcha with the user input:

    [HttpPost]
    public ActionResult Index(CaptchaModel model)
    {
        var realCaptcha = HttpContext.Session.GetString("captcha").ToLower();
        if (realCaptcha != model.Captcha)
            model.Message = "Ops...Wrong captcha!";
        else
            model.Message = "Congrats! Captcha has been matched!";
        return View(model);
    }
  • You can change the length of the captcha by the code below. (Default value is 5):

    <img src="~/Captcha?l=6" alt="Captcha" />
  • You can change the background color of the captcha by the code below either by writting the color name or the keyword random. (Default is transparent):

    <img src="~/Captcha?bc=black" alt="Captcha" />
    <img src="~/Captcha?bc=random" alt="Captcha" />
  • You can change the forecolor of the captcha by the code below either by writting the color name or the keyword random. (Default is random):

    <img src="~/Captcha?fc=green" alt="Captcha" />
  • You can change type of the characters. num for numeric characters or mix for alphanumeric characters. (Default is mix):

    <img src="~/Captcha?t=num" alt="Captcha" />

About

An efficient and secured alternative of Google reCAPTCHA for .NET Core

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%