asp.net C # Color Verification Code Picture Generation Program (1/3)

Source: Internet
Author: User
Tags rand

Color Verification Code pictures can defend against other people's attack?
Because when someone uses a polling technique to simulate a login, he doesn't know what your verification code is, can not get, because this is a picture, the computer does not recognize what the number is inside (unless you crack the verification code inside the interference, and then use the relevant image recognition technology may read out the verification code, here is not to pull this). Can not read the verification code will not have the opportunity to poll access, of course, we judge the background must first determine whether the verification code is correct to prevent the use of server resources.


3. Random number Code


① Digital Random number

1///<summary>
2///Digital Random number
3///</summary>
4///<returns></returns>
5 private string Getrndnum ()
6 {
7 String code = String.Empty;
8 random random = new random ();
9 for (int i = 0; i < 4; i++)
10 {
One code = code + RANDOM.NEXT (9). ToString ();
12}
return code;
14}

② string Random number

1///<summary>
2///String Verification code
3///</summary>
4///<returns></returns>
5 private string Getrndstr ()
6 {
7 String Vchar = "A,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
8 string[] Vcarray = Vchar.split (', ');
9 string checkcode = String.Empty;
Random rand = new Random ();
for (int i = 0; i < 4; i++)
12 {
Rand = new Random (unchecked (int) datetime.now.ticks);//To get a different random sequence
int t = rand.next (vcarray.length);/the exclusive upper bound of the random number to be generated. MaxValue must be greater than or equal to zero, subscript starting from 0
Checkcode + = vcarray[t];
16}
return checkcode;
18}

Home 1 2 3 last
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.