Getting Started

Prerequisites

Installation

This section will explain how to use ReCaptcha.Desktop with an UI framework. Generally the library is used the same for all UI frameworks, but there are a few small adjustments to the respective framework, such as naming conventions or UI related properties.

  • Step 1: Install ReCaptcha.Desktop package
dotnet add <PROJECT> package ReCaptcha.Desktop.WPF # WPF
dotnet add <PROJECT> package ReCaptcha.Desktop.WinUI # WinUI3
dotnet add <PROJECT> package ReCaptcha.Desktop.UWP # UWP
dotnet add <PROJECT> package ReCaptcha.Desktop.WinForms # WinForms 
  • Step 2: Import ReCaptcha.Desktop dependencies
// WPF
using ReCaptcha.Desktop.WPF.Client;
using ReCaptcha.Desktop.WPF.Client.Interfaces;
using ReCaptcha.Desktop.WPF.Configuration;
// WinUI
using ReCaptcha.Desktop.WinUI.Client;
using ReCaptcha.Desktop.WinUI.Client.Interfaces;
using ReCaptcha.Desktop.WinUI.Configuration;
// UWP
using ReCaptcha.Desktop.UWP.Client;
using ReCaptcha.Desktop.UWP.Client.Interfaces;
using ReCaptcha.Desktop.UWP.Configuration;
// WinForms
using ReCaptcha.Desktop.WinForms.Client;
using ReCaptcha.Desktop.WinForms.Client.Interfaces;
using ReCaptcha.Desktop.WinForms.Configuration;
WindowConfig uiConfig = new("WINDOW_TITLE"); // WPF
WindowConfig uiConfig = new("WINDOW_TITLE"); // WinUI3
PopupConfig uiConfig = new("POPUP_TITLE"); // UWP
FormConfig uiConfig = new("FORM_TITLE"); // WinForms 

ReCaptchaConfig config = new("SITE_KEY", "HOST_NAME");
IReCaptchaClient reCaptcha = new ReCaptchaClient(config, uiConfig);
  • Step 4: Hook events (Optional)
reCaptcha.VerificationRecieved += (s, e) =>
    MessageBox.Show($"Token: {e.Token}\nOccurred At: {e.OccurredAt}", "Verification recieved");

reCaptcha.VerificationCancelled += (s, e) =>
    MessageBox.Show($"Occurred At: {e.OccurredAt}", "Verification cancelled");
  • Step 4: Run verification

Running reCaptcha.VerifyAsync will show a new window on WPF and WinUI3. On WinForms a new form will be shown. Since multi windowing is really limited in UWP a popup will be shown instead.

CancellationTokenSource cts = new(TimeSpan.FromMinutes(1));
string token = await reCaptcha.VerifyAsync(cts.Token);

That's it!

As you can see this wasn't really difficult, was it? Now we can start learning about advanced stuff like configuring our ReCaptchaClient or widgets that look just like the original "I'm not a robot" widget.