Skip to content

ASP.NET Core hCaptcha Component for Server-Side Blazor.

License

Notifications You must be signed in to change notification settings

Texnomic/hCaptcha

Repository files navigation

Blazor

Texnomic.Blazor.hCaptcha

NuGet

ASP.NET Core hCaptcha Component for Server-Side Blazor.

Installation

PM> Install-Package Texnomic.Blazor.hCaptcha

Setup

  1. Reference hCaptcha & NuGet Package JavaScript Files In Pages/_Host.cshtml File:

    <head>
    
    <script src="https://hcaptcha.com/1/api.js&render=explicit" async type="text/javascript"></script>
    
    <script src="_content/Texnomic.Blazor.hCaptcha/scripts/hCaptcha.js" type="text/javascript"></script>
    
    </head>
  2. Add Package Configuration To Dependancy Injection Services in Startup.cs File:

    using Texnomic.Blazor.hCaptcha.Extensions;
    
    public void ConfigureServices(IServiceCollection Services)
    {
        Services.AddHttpClient();
        Services.AddHCaptcha(Options =>
        {
            Options.SiteKey = "10000000-ffff-ffff-ffff-000000000001";
            Options.Secret = "0x0000000000000000000000000000000000000000";
        });
    }
  3. Create Callback Function & Backing Field To Capture Captcha Result In Example.razor.cs File:

    private bool IsCaptchaValid { get; set; }
    
    protected void hCaptchaCallback(bool Result) => IsCaptchaValid = Result;
  4. Finally, Drop-In hCaptcha Component & Bind Callback Function In Example.razor File:

    <HCaptcha Callback="hCaptchaCallback" Theme="Theme.Dark"></HCaptcha>

Donations

  • PayPal
  • Bitcoin
  • Ethereum