Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.12 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5. #include <string.h>
  6.  
  7.  
  8. int main()
  9. {
  10.     FILE * user;
  11.     char choice;
  12.     char * username;
  13.     char * password1;
  14.     char * password2;
  15.     int i;
  16.     int j;
  17.     bool digit, upper, lower;
  18.  
  19.     username = (char *) malloc( 25 * sizeof(int) );
  20.     password1 = (char *) malloc( 25 * sizeof(int) );
  21.     password2 = (char *) malloc( 25 * sizeof(int) );
  22.  
  23.     printf("Do you have an account? <y/n>\n");
  24.     scanf(" %c", &choice);
  25.  
  26.     if(choice == 'n'){
  27.  
  28.         puts("\nWell its time to make one ...\n");
  29.         puts("Enter your username dude :");
  30.         scanf(" %s",username);
  31.         strcat(username, ".txt");
  32.         while(1){
  33.             while(1){
  34.                 puts("Enter your password and try to make it strong (use upper case and lower case letters and numbers) ");
  35.                 scanf(" %s",password1);
  36.                 for(i = 0; i < strlen(password1); i++){
  37.                     if( isdigit(password1[i]) ){
  38.                             digit = true;
  39.                     }else if( isalpha(password1[i]) ){
  40.  
  41.                         if( isupper(password1[i]) ){
  42.                             upper = true;
  43.                         }else{
  44.                             lower = true;
  45.                         }
  46.  
  47.                     }
  48.                 }
  49.  
  50.                 if(digit==true && upper==true && lower==true){
  51.                     break;
  52.                 }
  53.                 printf("Are you deaf? I said a strong password!!!\n");
  54.             }
  55.             puts("Reenter the pasword :");
  56.             scanf(" %s", password2);
  57.  
  58.             j=0;
  59.             for(i=0; i<strlen(password1); i++){
  60.                 if(password1[i] == password2[i]){
  61.                     j++;
  62.                 }
  63.             }
  64.             if(strlen(password1) == strlen(password2) && i == j){
  65.                     break;
  66.                     }
  67.             puts("That isn't your password...");
  68.         }
  69.         user = fopen(username, "w");;
  70.         fprintf(user, "%s", password1);
  71.     }else{
  72.         while(1){
  73.             puts("Then enter your username : ");
  74.             scanf(" %s", username);
  75.             strcat(username, ".txt");
  76.             user = fopen(username, "r");
  77.  
  78.             while(!feof(user)){
  79.                 fgets(password2, 25, user);
  80.             }
  81.  
  82.             puts("Enter your password : ");
  83.             scanf(" %s", password1);
  84.  
  85.             j=0;
  86.             for(i=0; i<strlen(password1); i++){
  87.                 if(password1[i] == password2[i]){
  88.                     j++;
  89.                 }
  90.             }
  91.             if(strlen(password1) == strlen(password2) && i == j){
  92.                     puts("Well your in ... What do you want to do, because there is nothing to do... :(");
  93.                     }else{
  94.                         puts("It seems that you don't have an account, or maybe you entered your username/password incorrectly.");
  95.                         puts("Please try again.");
  96.                     }
  97.             }
  98.     }
  99.    
  100.     fclose(user);
  101.     free(username);
  102.     free(password1);
  103.     free(password2);
  104.  
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement