This project implements a unique captcha validation system using React and webcam functionality. Users are required to take a selfie and then identify specific shapes and colors within the captured image to pass the captcha.
Before you begin, ensure you have met the following requirements:
- Node.js (version 12.0 or higher recommended)
- npm (usually comes with Node.js)
- A modern web browser with webcam support
To install the project, follow these steps:
- Clone the repository: https://github.com/labibahmed10/captcha-test.git
- Navigate to the project directory:
cd captcha-test/
- Install the dependencies:
npm install
To run the project locally:
- Start the development server:
npm run dev
- Open your web browser and navigate to
http://localhost:3000
- Allow camera access when prompted by your browser
- Follow the on-screen instructions to complete the captcha
Webcam Integration:
Uses react-webcam for selfie capture.Dynamic Captcha Generation:
Creates a grid with random shapes and colors.Interactive Selection:
Allows users to click on grid sectors.Validation System:
Checks user selections against the generated captcha.Multiple Attempts:
Tracks and limits failed validation attempts.Temporary Blocking:
Implements a blocking mechanism after multiple failures.
CaptchaContainer
: Wrapper component for the captcha interfaceCaptchaWebCamContainer
: Handles webcam integration and image captureCaptchaSectorsValidation
: Manages the captcha validation processBlockedError
: Displays when user is blocked after 5 failed attempts
The main component that orchestrates the captcha flow. It manages the state and logic for:
- Capturing the selfie
- Generating the captcha grid
- Validating user selections
- Handling failed attempts and user blocking
A wrapper component that provides a consistent layout for different stages of the captcha process. It displays:
- The captcha title
- The main content (webcam or captcha grid)
- Action button
- Feedback messages
Handles the display and interaction of the captcha grid after a selfie is taken. Features include:
- Displaying the captured selfie
- Overlaying an interactive grid
- Rendering shape watermarks (triangle, circle, square)
- Handling user selections
Manages the webcam functionality for capturing the selfie. It:
- Initializes the webcam
- Displays the live webcam feed
- Shows a positioning guide for the captcha grid
The project uses a combination of Tailwind CSS and custom styles. Key styling features include:
- Responsive design with flexbox
- Custom shapes for captcha watermarks
- Interactive hover and active states
- Dynamic positioning of the captcha grid
- User is prompted to take a selfie.
- A grid is overlaid on the captured image.
- Random grid sectors are filled with colored shapes.
- User is instructed to select sectors with a specific shape and color.
- Selections are validated, and feedback is provided.
- After multiple failed attempts, the user is temporarily blocked for one hour
- React
- typescript
- react-webcam
- Tailwind CSS
- sweetalert2