Password verification using file read/write

Source: Internet
Author: User

During this period of time, you can use vs2010 to connect to the database to ensure the password and password verification.

But here I think of a pseudo-password verification problem implemented by using files. For details, refer. The implementation code is as follows:

Code:

1 # include <stdio. h> 2 # include <string. h> 3 # define max 100 4 5 Int main () 6 {7 file * FP; 8 fp = fopen ("F: \ secret. PWD "," R "); // open" F: \ secret in read-only mode. PWD "9 If (FP = NULL) 10 {11 printf (" can not open this file. \ n "); 12} 13 else14 {15 char C [Max], ch; 16 memset (C, 0, sizeof (c); 17 CH = fgetc (FP ); 18 int I; 19 char mycode [Max]; 20 for (I = 0; ch! = EOF; ++ I) // assign the string in the file to C [] 21 {22 C [I] = CH; 23 CH = fgetc (FP) before the terminator ); 24} 25 int Len = strlen (c); // take the length of the C string 26 if (LEN) // The length is 0, that is, there is no string 27 {28 scanf ("% s", mycode); 29 If (! Strcmp (mycode, c) // verify that the two strings are equal to 30 {31 printf ("right code. \ n "); 32} 33 else34 {35 printf (" Wrong code. \ n "); 36} 37} 38 else39 {40 printf (" Please input password. \ n "); 41 scanf (" % s ", mycode); 42 fp = fopen (" F: \ secret. PWD "," W "); 43 fprintf (FP," % s ", mycode); 44} 45} 46 fclose (FP); // close file 47 return 0; 48}

 

Some other operations on files are visible: http://www.cnblogs.com/edward259/archive/2010/01/13/1646339.html

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.