# Captcha

The Captcha module presents a CAPTCHA challenge during onboarding to verify human interaction and reduce automated abuse. It then returns the user's response to your app.

In Dashboard, Captcha isn't a standalone module. Instead, enable one-time password (OTP) verification in the settings of the [Email Input](https://developer.incode.com/docs/email-input-dashboard) and [Phone Number Input](https://developer.incode.com/docs/phone-number-input-dashboard) modules.

How you use this module depends on your integration pattern. When your app defines the steps in code, you add the module to an `IncdOnboardingFlowConfiguration` as shown below; when the flow is defined in Dashboard, you reference it by session token and let the back end drive the steps. See [Integration Approaches](https://developer.incode.com/docs/ios-flow-configuration).

**Availability:** All variants.

## Add Captcha

Add the module with `addCaptcha()`. It takes no parameters.

```swift
flowConfig.addCaptcha()
```

### Example

The example below adds Captcha as the only step in the flow and reads the result from the `onCaptchaCompleted(_:)` delegate callback.

```swift
let flowConfig = IncdOnboardingFlowConfiguration()
flowConfig.addCaptcha()

IncdOnboardingManager.shared.startOnboarding(
    sessionConfig: IncdOnboardingSessionConfiguration(token: "<SESSION_TOKEN>"),
    flowConfig: flowConfig,
    delegate: self
)
```

```swift
// IncdOnboardingDelegate
func onCaptchaCompleted(_ result: CaptchaResult) {
    // CAPTCHA step completed. Process the result.
}
```

## Configuration Options

Captcha has no configurable options.

## Result

Captcha delivers a `CaptchaResult` to the `onCaptchaCompleted(_:)` callback on `IncdOnboardingDelegate`.

```swift
func onCaptchaCompleted(_ result: CaptchaResult)
```

`CaptchaResult` fields:

- `captcha: String?`: The entered CAPTCHA value. `nil` when the step did not complete successfully.
- `error: CaptchaError?`: Set when the step failed; otherwise, `nil`.

## Errors

Failures surface through `CaptchaResult.error` as a `CaptchaError`:

- `error(IncdError)`: Wraps an underlying `IncdError`.
- `wrongCaptchaEntered`: The value entered did not match.
- `captchaNotGenerated`: No CAPTCHA was generated for the session.

<br />
