All Projects → hCaptcha → react-hcaptcha

hCaptcha / react-hcaptcha

Licence: MIT License
hCaptcha Component Library for ReactJS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-hcaptcha

2captcha-php
PHP package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
Stars: ✭ 25 (-85.21%)
Mutual labels:  captcha, hcaptcha
2captcha-python
Python 3 package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
Stars: ✭ 140 (-17.16%)
Mutual labels:  captcha, hcaptcha
dcat-auth-captcha
Sliding captcha for dcat-admin auth / dcat-admin登陆 滑动验证插件 多平台支持
Stars: ✭ 38 (-77.51%)
Mutual labels:  captcha, hcaptcha
2captcha-go
Golang Module for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
Stars: ✭ 31 (-81.66%)
Mutual labels:  captcha, hcaptcha
hcaptcha-bundle
A Symfony 4+ bundle to bring hCaptcha into your forms
Stars: ✭ 15 (-91.12%)
Mutual labels:  captcha, hcaptcha
hcaptcha-solver-python-selenium
hCaptcha solver and bypasser for Python Selenium. Simple website to try to solve hCaptcha.
Stars: ✭ 32 (-81.07%)
Mutual labels:  captcha, hcaptcha
Captcha-Tools
All-in-one Python (And now Go!) module to help solve captchas with Capmonster, 2captcha and Anticaptcha API's!
Stars: ✭ 23 (-86.39%)
Mutual labels:  captcha, hcaptcha
captcha-breaking-library
Neural network, contour analysis, bitmap vector subtraction CAPTCHA solving library and scripting language with perceptive color space segmentation
Stars: ✭ 76 (-55.03%)
Mutual labels:  captcha
Slider Captcha Crack
🌈Slider_Captcha_Crack某教育网站滑动验证码破解(识别率100%)
Stars: ✭ 49 (-71.01%)
Mutual labels:  captcha
eros-plugin-ios-TencentCaptcha
腾讯防水墙、滑动验证、类似bilibili滑动验证码
Stars: ✭ 21 (-87.57%)
Mutual labels:  captcha
adonis-recaptcha2
Google reCAPTCHA for AdonisJS
Stars: ✭ 24 (-85.8%)
Mutual labels:  captcha
imagetyperz-api-python3
imagetyperz-api-python3 - is a super easy to use bypass captcha API wrapper for imagetyperz.com captcha service
Stars: ✭ 25 (-85.21%)
Mutual labels:  captcha
League-of-Legends-Accounts-Creator
Accounts Creator for League of Legends.
Stars: ✭ 46 (-72.78%)
Mutual labels:  captcha
Z-Spider
一些爬虫开发的技巧和案例
Stars: ✭ 33 (-80.47%)
Mutual labels:  captcha
breakingcaptcha
Breaking captchas!!
Stars: ✭ 38 (-77.51%)
Mutual labels:  captcha
SimCaptcha
✅ 一个简单易用的点触验证码 (前端+后端)
Stars: ✭ 49 (-71.01%)
Mutual labels:  captcha
bypass-captcha-examples
Different complex captcha bypass examples: Steam, Netflix, Data Dome, Adobe, etc.
Stars: ✭ 62 (-63.31%)
Mutual labels:  captcha
phone-captcha
📱 Block robocalls with captcha for phone calls
Stars: ✭ 32 (-81.07%)
Mutual labels:  captcha
CaptchaSolver
Um simples projeto para fazer o reconhecimento do captcha usado pelo jogo bombcrypto.
Stars: ✭ 52 (-69.23%)
Mutual labels:  captcha
recaptcha
An easy-to-use reCAPTCHA package
Stars: ✭ 55 (-67.46%)
Mutual labels:  captcha

React hCaptcha Component Library

Description

hCaptcha Component Library for ReactJS.

hCaptcha is a drop-replacement for reCAPTCHA that protects user privacy, rewards websites, and helps companies get their data labeled.

Sign up at hCaptcha to get your sitekey today. You need a sitekey to use this library.

Installation

You can install this library via npm with:

npm install @hcaptcha/react-hcaptcha --save

Usage

The two requirements for usage are the sitekey prop and a parent component such as a <form />. The component will automatically include and load the hCaptcha API library and append it to the parent component. This is designed for ease of use with the hCaptcha API!

Basic Usage

import HCaptcha from '@hcaptcha/react-hcaptcha';

<FormComponent>
    <HCaptcha
      sitekey="your-sitekey"
      onVerify={(token,ekey) => handleVerificationSuccess(token, ekey)}
    />
</FormComponent>

A note about TypeScript usage: If you want to reassign the component name, you could consider making a util that imports the component, then re-exports it as a default. Example:

// utils/captcha.ts
import HCaptcha from '@hcaptcha/react-hcaptcha';
export default HCaptcha;

// MyFormComponent.tsx
import { default as RenamedCaptcha } from '../utils/captcha';
<FormComponent>
  <RenamedCaptcha sitekey="your-sitekey" />
</FormComponent>

Programmatic Usage

In the event you want to call the hCaptcha client API directly, you can do so by using the hook useRef and waiting for onLoad to be called. By waiting for onLoad the hCaptcha API will be ready and the hCaptcha client will have been setup. See the following example:

import { useEffect, useRef, useState } from "react";
import HCaptcha from "@hcaptcha/react-hcaptcha";

export default function Form() {
  const [token, setToken] = useState(null);
  const captchaRef = useRef(null);

  const onLoad = () => {
    // this reaches out to the hCaptcha JS API and runs the
    // execute function on it. you can use other functions as
    // documented here:
    // https://docs.hcaptcha.com/configuration#jsapi
    captchaRef.current.execute();
  };

  useEffect(() => {

    if (token)
      console.log(`hCaptcha Token: ${token}`);

  }, [token]);

  return (
    <form>
      <HCaptcha
        sitekey="your-sitekey"
        onLoad={onLoad}
        onVerify={setToken}
        ref={captchaRef}
      />
    </form>
  );
}

Advanced usage

In most real-world implementations, you'll probably be using a form library such as Formik or React Hook Form.

In these instances, you'll most likely want to use ref to handle the callbacks as well as handle field-level validation of a captcha field. For an example of this, you can view this CodeSandbox. This ref will point to an instance of the hCaptcha API where can you interact directly with it.

Passing in fields like rqdata to execute()

Passing an object into the execute(yourObj) call will send it through to the underlying JS API. This enables support for Enterprise features like rqdata. A simple example is below:

const {sitekey, rqdata} = props;
const captchaRef = React.useRef<HCaptcha>(null);

const onLoad = () => {
  const executePayload = {};
  if (rqdata) {
    executePayload['rqdata'] = rqdata;
  }
  captchaRef.current?.execute(executePayload);
};

return <HCaptcha ref={captchaRef} onLoad={onLoad} sitekey={sitekey} {...props} />;

Props

Name Values/Type Required Default Description
sitekey String Yes - This is your sitekey, this allows you to load captcha. If you need a sitekey, please visit hCaptcha, and sign up to get your sitekey.
size String (normal, compact, invisible) No normal This specifies the "size" of the component. hCaptcha allows you to decide how big the component will appear on render, this always defaults to normal.
theme String (light, dark) No light hCaptcha supports both a light and dark theme. If no theme is inherently set, the captcha will always default to light.
tabindex Integer No 0 Set the tabindex of the widget and popup. When appropriate, this can make navigation of your site more intuitive.
languageOverride String (ISO 639-2 code) No auto hCaptcha auto-detects language via the user's browser. This overrides that to set a default UI language. See language codes.
reCaptchaCompat Boolean No true Disable drop-in replacement for reCAPTCHA with false to prevent hCaptcha from injecting into window.grecaptcha.
id String No random id Manually set the ID of the hCaptcha component. Make sure each hCaptcha component generated on a single page has its own unique ID when using this prop.
apihost String No - See enterprise docs.
assethost String No - See enterprise docs.
endpoint String No - See enterprise docs.
host String No - See enterprise docs.
imghost String No - See enterprise docs.
reportapi String No - See enterprise docs.
sentry String No - See enterprise docs.
custom Boolean No - See enterprise docs.

Events

Event Params Description
onError err When an error occurs. Component will reset immediately after an error.
onVerify token, eKey When challenge is completed. The response token and an eKey (session id) are passed along.
onExpire - When the current token expires.
onLoad - When the hCaptcha API loads.
onOpen - When the user display of a challenge starts.
onClose - When the user dismisses a challenge.
onChalExpired - When the user display of a challenge times out with no answer.

Methods

Method Description
execute() Programmatically trigger a challenge request. Additionally, this method can be run asynchronously and returns a promise with the token and eKey when the challenge is completed.
resetCaptcha() Reset the current challenge

NOTE: Make sure to reset the hCaptcha state when you submit your form by calling the method .resetCaptcha on your hCaptcha React Component! Passcodes are one-time use, so if your user submits the same passcode twice then it will be rejected by the server the second time.

Please refer to the demo for examples of basic usage and an invisible hCaptcha.

Alternatively, see this sandbox code for a quick form example of invisible hCaptcha on a form submit button.

Please note that "invisible" simply means that no hCaptcha button will be rendered. Whether a challenge shows up will depend on the sitekey difficulty level. Note to hCaptcha Enterprise (BotStop) users: select "Passive" or "99.9% Passive" modes to get this No-CAPTCHA behavior.


Note for maintainers

Scripts

  • npm run start - will start the demo app with hot reload
  • npm run test - will test the library: unit tests
  • npm run build - will build the production version

Publishing

To publish a new version, follow the next steps:

  1. Bump the version in package.json
  2. Create a Github Release with version from step 1 without a prefix such as v (e.g. 1.0.3)

Running locally for development

Please see: Local Development Notes.

Summary:

sudo echo "127.0.0.1 fakelocal.com" >> /private/etc/hosts

npm start -- --disable-host-check

open http://fakelocal.com:9000 to start the example.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].