Socket
Book a DemoInstallSign in
Socket

navid-react-captcha-generator

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

navid-react-captcha-generator

navid-react-captcha-generator is a fully customizable CAPTCHA generator for React applications. It provides advanced image manipulation features like random-sized and distorted letters, background noise, and security lines, making it harder for bots to de

1.0.2
latest
npmnpm
Version published
Maintainers
0
Created
Source

React CAPTCHA Component

npm npm License

A customizable CAPTCHA component for React, allowing various styles and configurations to protect forms from bots.

Features

  • Customizable dimensions and font sizes
  • Background and text colors
  • Noise and lines for added security
  • Distortion effects
  • Individual character styles
  • Regeneration on demand

Installation

To install the package via npm:

npm install navid-react-captcha-generator

Or with yarn:

yarn add navid-react-captcha-generator

Usage

Here’s a basic example of how to use the Captcha component:

import { useState } from "react";
import { Captcha } from "navid-react-captcha-generator";

function App() {
  const [captchaValue, setCaptchaValue] = useState("");
  const [regenerate, setRegenerate] = useState(false);

  const handleCaptchaChange = (value: string) => {
    setCaptchaValue(value);
  };

  const regenerateCaptcha = () => {
    setRegenerate((prev) => !prev);
  };

  return (
    <div>
      <Captcha
        onChange={handleCaptchaChange}
        regenerate={regenerate}
        width={200}
        height={50}
        length={5}
        fontSize={24}
        bgColor="#fff"
        textColor="#000"
        noise={true}
        lines={true}
        distortion={true}
      />
      <p>Captcha Value: {captchaValue}</p>
      <button onClick={regenerateCaptcha}>Regenerate Captcha</button>
    </div>
  );
}

export default App;

Props

PropTypeDefaultDescription
widthnumber200Width of the CAPTCHA canvas.
heightnumber50Height of the CAPTCHA canvas.
lengthnumber6Number of characters in the CAPTCHA text.
fontSizenumber30Font size of the CAPTCHA text.
bgColorstring#ffffffBackground color of the CAPTCHA canvas.
textColorstring | string[]#000000Color of the CAPTCHA text; can be a single color or an array of colors for individual characters.
noisebooleantrueWhether to add noise to the CAPTCHA.
noiseColorstring#000000Color of the noise.
noiseDensitynumber0.05Density of the noise; control how much noise is added.
linesbooleantrueWhether to add random lines to the CAPTCHA.
lineColorstring#000000Color of the lines.
lineWidthnumber1Width of the lines.
distortionbooleantrueWhether to apply distortion effects to the CAPTCHA.
distortionAmountnumber4Amount of distortion applied.
onChange(captcha: string) => voidundefinedCallback function that is called when the CAPTCHA value changes.
regeneratebooleanfalsetriggers CAPTCHA regeneration by changing false and true.
charStyles{ [key: number]: { size?: number; color?: string } }{}Individual styles for each character, including size and color.

Examples

Example 1: Basic Usage

Example 1

<Captcha
  width={200}
  height={50}
  length={5}
  fontSize={24}
  bgColor="#fff"
  textColor="#000"
  noise={true}
  lines={true}
  distortion={true}
/>

Example 2: Custom Colors and Noise

Example 2

<Captcha
  width={300}
  height={60}
  length={8}
  fontSize={28}
  bgColor="#000000"
  textColor={["#ff0000", "#00ff00", "#0000ff"]}
  noiseColor="#aaaaaa"
  noiseDensity={0.1}
  lines={true}
  lineColor="#cccccc"
  lineWidth={2}
  distortion={true}
  distortionAmount={6}
/>

Example 3: Individual Character Styles

Example 3

<Captcha
  width={250}
  height={70}
  length={6}
  fontSize={36}
  bgColor="#fafafa"
  textColor="#000"
  noise={true}
  lines={false}
  distortion={false}
  charStyles={{
    0: { size: 40, color: "#ff0000" },
    1: { size: 30, color: "#00ff00" },
    2: { size: 35, color: "#0000ff" },
    3: { size: 32, color: "#ff00ff" },
    4: { size: 38, color: "#00ffff" },
    5: { size: 30, color: "#ffff00" },
  }}
/>

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Navid Mousavizadeh

FAQs

Package last updated on 25 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.