- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to generate CAPTCHA and verify user
In this tutorial, we will be discussing a program to generate CAPTCHA and verify user.
For this, we will provide the user with a random string and ask him to reenter the same string. Then it has to be checked if the given and the input string matches.
The CAPTCHA should be completely random system generated consisting of a-z, AZ and 0-9.
Example
#include<bits/stdc++.h> using namespace std; //checks if the strings are same bool check_string(string &captcha, string &user_captcha){ return captcha.compare(user_captcha) == 0; } //generates a random string as Captcha string gen_captcha(int n){ time_t t; srand((unsigned)time(&t)); char *chrs = "abcdefghijklmnopqrstuvwxyzABCDEFGHI" "JKLMNOPQRSTUVWXYZ0123456789"; string captcha = ""; while (n--) captcha.push_back(chrs[rand()%62]); return captcha; } int main(){ string captcha = gen_captcha(9); cout << captcha; string usr_captcha; cout << "\nEnter CAPTCHA : "; usr_captcha = "fgyeugs56"; if (check_string(captcha, usr_captcha)) printf("\nCAPTCHA Matched"); else printf("\nCAPTCHA Not Matched"); return 0; }
Output
nwsraJhiP Enter CAPTCHA : CAPTCHA Not Matched
- Related Articles
- C++ Program to Generate Multiplication Table
- C++ program to generate random number
- C++ program to generate random alphabets
- The Story of Captcha and its Variants
- C++ Program to Generate Random Hexadecimal Bytes
- C# Program to generate random lowercase letter
- C# program to generate secure random numbers
- C program to generate an electricity bill
- C++ Program to Print Number Entered by User
- Write a program in Python to verify camel case string from the user, split camel cases, and store them in a new series
- Java program to generate and print Floyd’s triangle
- How to add a captcha in a Django website?
- C++ Program to Generate a Random Subset by Coin Flipping
- C++ Program to Generate Random Numbers Using Middle Square Method
- C++ Program to Generate Random Numbers Using Probability Distribution Function

Advertisements