notoroius2pac

login with hidden password

Aug 7th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.78 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<conio.h>
  5.  
  6. int option;
  7.  
  8. struct data
  9. {
  10.     char name[50],pass[50];
  11. }inputdata,odata;
  12.  
  13. void login();                           //function to login
  14. void signup();                          // function to store data of new user
  15. void password();                        // function to store password with hiding it too
  16. void logincheck();                      //function to check username and pass word entered by the user
  17. void signupcheck();                     // function to check the username so that it wont repeat
  18. void write();                           // function to store user data
  19.  
  20. int main()
  21. {
  22.     printf("1. LOGIN \n 2.SIGNUP \n");
  23.     scanf("%d",&option);
  24.          switch(option)
  25.          {
  26.              case 1:    login();
  27.                         break;
  28.              case 2:    signup();
  29.                         break;
  30.              default :  printf("\n INCORRECT CHOICE !!!!");
  31.          }
  32.     return 0;
  33. }
  34.  
  35. void login()
  36. {
  37.     printf("Enter your username :- ");
  38.     scanf("%s",inputdata.name);
  39.     printf("Enter your password :- ");
  40.     password();
  41.     logincheck();
  42. }
  43.  
  44. void signup()
  45. {
  46.     printf("Enter your username :- ");
  47.     scanf("%s",inputdata.name);
  48.     printf("Enter your password :- ");
  49.     signupcheck();
  50. }
  51.  
  52.  void password()
  53.             {
  54.             int i=0,run;
  55.             char temp;
  56.                 do
  57.                 {
  58.                     temp=getch();
  59.                     if(temp!='\r'||temp=='\b')
  60.                     {
  61.  
  62.                           if(temp=='\b')
  63.                         {
  64.                         --i;
  65.                         //inputdata.pass[i]='\0';
  66.                         system("CLS");
  67.  
  68.                              printf("1. LOGIN \n 2.SIGNUP \n %d", option);
  69.                              printf("\n Enter your username :- %s ",inputdata.name);
  70.                              printf("\n Enter your password :- ");
  71.                         for(run=0;run<i;++run)
  72.                             printf("*");
  73.                         }
  74.                         else
  75.                         {
  76.                         inputdata.pass[i]= temp;
  77.                         ++i;
  78.                         printf("*");
  79.                         }
  80.                     }
  81.                     else
  82.                        {
  83.                        //printf("You Pressed Enter %s" ,inputdata.pass);
  84.                        break;
  85.                        }
  86.                 }while(i<=49);
  87.             }
  88.  
  89.     void signupcheck()
  90.     {
  91.     FILE *check;
  92.     check=fopen("data.txt","r");
  93.       while(!feof(check))
  94.                  {
  95.                      fread(odata.name,1,sizeof(odata.name),check);
  96.                      fread(odata.pass,1,sizeof(odata.pass),check);
  97.                      if(strcmp(inputdata.name,odata.name)==0)
  98.                      {
  99.                         printf("\n THIS USERNAME IS ALREADY IN USE PLEASE CHOOSE ANOTHER USERNAME !!!");
  100.                         break;
  101.                      }
  102.                      else
  103.                         password();
  104.                         write();
  105.                  }
  106.                  fclose(check);
  107.     }
  108.  
  109.         void logincheck()                                 //loginchck function!!!!!!
  110.         {
  111.             FILE *out;
  112.                if((out=fopen("data.txt","r"))==NULL)
  113.                    {
  114.                        printf("ERROR IN OPENING FILE");
  115.                        system("pause");
  116.                    }
  117.                  while(!feof(out))
  118.                  {
  119.                      fread(odata.name,1,sizeof(odata.name),out);
  120.                      fread(odata.pass,1,sizeof(odata.pass),out);
  121.                      if(strcmp(inputdata.name,odata.name)==0)
  122.                      {
  123.                          if(strcmp(inputdata.pass,odata.pass)==0)
  124.                          {
  125.                              printf("\n LOGIN SUCCESSFUL !!!");
  126.                              break;
  127.                          }
  128.                          else
  129.                              printf("\n LOGIN FAILED !!!");
  130.                              break;
  131.                      }
  132.                      else
  133.                      {
  134.                          printf("\nINCORRECT USERNAME !!!!");
  135.                          break;
  136.                      }
  137.                  }
  138.                  fclose(out);
  139.         }
  140.  
  141.             void write()
  142.             {
  143.                 FILE *in;
  144.                 if((in=fopen("data.txt","w"))==NULL)
  145.                    {
  146.                        printf("ERROR IN OPENING FILE");
  147.                        system("pause");
  148.                    }
  149.                 fwrite(inputdata.name,1,sizeof(inputdata.name),in);
  150.                 fwrite(inputdata.pass,1,sizeof(inputdata.pass),in);
  151.                 fclose(in);
  152.             }
Add Comment
Please, Sign In to add comment