Captcha Generator
React.js
medium
30 mins
Build a simple CAPTCHA generator component in React that:
- Generates a random alphanumeric string on page load or when the user requests a refresh.
- Displays the string using visual distortion such as skewing, rotation, or styled text.
- Accepts user input and compares it against the CAPTCHA for validation.
- Allows the user to reload the CAPTCHA if they find it difficult to read.
Requirements
Captcha Logic
- The CAPTCHA should consist of a 5 to 6 character alphanumeric string (A–Z, 2–9).
- Use
Math.random()or similar to generate the characters. - Avoid confusing characters such as
O,0,1, andI.
Visual Rendering
- Render each character in the CAPTCHA using individual
<span>elements. - Apply random visual styling to each character using rotation, skew, font weight, etc.
- The visual styling should make the CAPTCHA harder to read by bots, but still legible to users.
User Interaction
- Include an input field where users can type the CAPTCHA.
- Add a button labelled
Submit-- If the input matches the CAPTCHA, show a message labelled
Correct - If the input does not matches the CAPTCHA, show a message labelled
Incorrect
- If the input matches the CAPTCHA, show a message labelled
- Add a
Regeneratebutton to refresh the CAPTCHA and reset the input and message.
Testing Instructions
- The heading
Captcha Generatoris rendered. - The CAPTCHA string is displayed using styled characters.
- The buttons must be labelled
SubmitandRegenerate. - Typing in the input and submitting with an incorrect string shows a message -
Incorrect. - Typing the correct CAPTCHA string shows a success message -
Correct. - Clicking the "Regenerate" button changes the CAPTCHA and clears previous input and messages.
Reference UI

Preview what you need to build
Companies:
microsoft
apple
linkedin
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
