Program to generate CAPTCHA and verify user | Python program to automatically generate CAPTCHA and verify user ; Returns true if given two strings are same ; Generates a CAPTCHA of given length ; Characters to be included ; Generate n characters from above set and add these characters to captcha . ; Generate a random CAPTCHA ; Ask user to enter a CAPTCHA ; Notify user about matching status
import random NEW_LINE def checkCaptcha ( captcha , user_captcha ) : NEW_LINE INDENT if captcha == user_captcha : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def generateCaptcha ( n ) : NEW_LINE INDENT chrs = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" NEW_LINE captcha = " " NEW_LINE while ( n ) : NEW_LINE INDENT captcha += chrs [ random . randint ( 1 , 1000 ) % 62 ] NEW_LINE n -= 1 NEW_LINE DEDENT return captcha NEW_LINE DEDENT captcha = generateCaptcha ( 9 ) NEW_LINE print ( captcha ) NEW_LINE print ( " Enter ▁ above ▁ CAPTCHA : " ) NEW_LINE usr_captcha = input ( ) NEW_LINE if ( checkCaptcha ( captcha , usr_captcha ) ) : NEW_LINE INDENT print ( " CAPTCHA ▁ Matched " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " CAPTCHA ▁ Not ▁ Matched " ) NEW_LINE DEDENT