Generation and verification of the >c language---verification codes generated by < verification codes

Source: Internet
Author: User

No matter in the Web page or the software on the login time will encounter the problem of verification code, do not know the secret of the Code of the Friends have no interest together to explore.

In fact, there is no mystery, that is, to generate random numbers, and then let the resulting random number as the word repertoires (pre-made digital letter string) subscript, so from the word repertoires randomly extracted from the composition of the small string is the simplest string, of course, you can create your own word repertoires content.

   Here is the code for the process of writing the verification Code and verifying the verification code in C language:

#include <stdio.h>#include<stdlib.h>#include<time.h>#include<string.h>#defineN 5voidIdentifying_code (CharStr[],intN) {intI,j,len; CharPstr[] ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJLMNOPQRSTUVWXYZ"; Len= strlen (PSTR);//to find the length of a string pstrSrand (Time (0));  for(i =0; i < n; i++) {J= rand ()%len;//generate a random number of 0~len-1Str[i] =Pstr[j]; } Str[i]=' /';}intMain () {intn =3; intFlag =0; Charcode[n+1],str[n+1];  while(n) {identifying_code (code,n); printf ("Please enter the verification code < You have%d chance >:%s\n", N,code); scanf ("%s", str); N--; if(strcmp (code,str) = =0) {//case-sensitive verification coden =0; Flag=1; printf ("verify correct. \ n"); }    }    if(Flag = =0) printf ("Sorry, your account is locked. \ n"); return 0; }

Welcome code Friends Comments, I will continue to modify to make it perfect, thank you for your support.

Generation and verification of the >c language---verification codes generated by < verification codes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.