A CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is a test to determine whether the user is human or not. So, the task is to generate unique CAPTCHA every time and to tell whether the user is human or not by asking user to enter the same CAPTCHA as generated automatically and checking the user input with the generated CAPTCHA. Examples:
The set of characters to generate CAPTCHA are stored in a character array chrs which contains (a-z, A-Z, 0-9), therefore size of chrs is 62. To generate a unique CAPTCHA every time, a random number is generated using rand() function (rand()%62) which generates a random number between 0 to 61 and the generated random number is taken as index to the character array chrs thus generates a new character of captcha and this loop runs n (length of CAPTCHA) times to generate CAPTCHA of given length.
// C++ program to automatically generate CAPTCHA and
Enter CAPTCHA: cF3yl9T4
Time Complexity: O(n) Space Complexity: O(1) This article is contributed by Himanshu Gupta(Bagri). If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Please Login to comment...