Class NuvCaptcha
- Assembly
- NuvTools.Security.AspNetCore.Blazor.dll
Reusable adaptive CAPTCHA (Google reCAPTCHA Enterprise) for public screens.
public class NuvCaptcha : ComponentBase, IComponent, IHandleEvent, IHandleAfterRender, IAsyncDisposable
- Inheritance
-
NuvCaptcha
- Implements
- Inherited Members
Remarks
Runs invisible by default (score key, via execute) — nothing appears on screen. When the
server flags the risk as high, the form calls RequireStepUpAsync() and the component
renders the checkbox challenge (checkbox key) as a step-up. Driven by
CaptchaOptions, registered with AddCaptcha.
Properties
Class
CSS class applied to the element that hosts the checkbox widget.
[Parameter]
public string? Class { get; set; }
Property Value
IsStepUp
Whether the component is already in checkbox (step-up) mode.
public bool IsStepUp { get; }
Property Value
Methods
BuildRenderTree(RenderTreeBuilder)
Renders the component to the supplied RenderTreeBuilder.
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
__builderRenderTreeBuilder
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
GetTokenAsync()
Gets the current token and mode. Without step-up: the invisible score token. In step-up: the checkbox token. When disabled, returns a non-empty token, since the server also skips verification in that mode.
public Task<(string? Token, string Mode)> GetTokenAsync()
Returns
HandleStepUpAsync(IResult)
Enters checkbox mode and returns true when the result carries the step-up marker (low
score), meaning the caller should stop and let the user solve the challenge.
public Task<bool> HandleStepUpAsync(IResult result)
Parameters
resultIResultThe result returned by the server call.
Returns
OnAfterRenderAsync(bool)
Method invoked after each time the component has been rendered interactively and the UI has finished updating (for example, after elements have been added to the browser DOM). Any ElementReference fields will be populated by the time this runs.
This method is not invoked during prerendering or server-side rendering, because those processes are not attached to any live browser DOM and are already complete before the DOM is updated.
Note that the component does not automatically re-render after the completion of any returned Task, because that would cause an infinite render loop.
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
firstRenderboolSet to
trueif this is the first time OnAfterRender(bool) has been invoked on this component instance; otherwisefalse.
Returns
Remarks
The OnAfterRender(bool) and OnAfterRenderAsync(bool) lifecycle methods
are useful for performing interop, or interacting with values received from @ref.
Use the firstRender parameter to ensure that initialization work is only performed
once.
RequireStepUpAsync()
Enters step-up: renders the checkbox for the user to confirm they are human.
public Task RequireStepUpAsync()
Returns
ResetAsync()
Clears the checkbox challenge for a new attempt — the token is single-use.
public Task ResetAsync()