Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.91 KB | None | 0 0
  1. int logIn(){
  2.  
  3.     char uName[100], uPass[100];
  4.     int i, j;
  5.     bool exists = false;
  6.  
  7.     while(true) {
  8.         printf("Username: ");
  9.         scanf("%s", uName);
  10.  
  11.         for (i = 0; i < 10; i++) {
  12.             exists = false;
  13.             if(strcmp(a[i].Username,uName) == 0){
  14.                 exists = true;
  15.                 j = i;
  16.                 break;
  17.             }
  18.         }
  19.  
  20.         if(exists = true){
  21.             printf("Password: ");
  22.             scanf("%s",uPass);
  23.  
  24.             if(strcmp(a[i].Password,uPass) == 0){
  25.                 printf("Success!");
  26.                 return j;
  27.             }
  28.  
  29.             else{
  30.                 printf("Account doesn't exist or the password is wrong! Try again.");
  31.                 continue;
  32.             }
  33.         }
  34.     }
  35. }
  36.  
  37. void accCreate(){
  38.     char username[100], password[100];
  39.     int i;
  40.     bool taken;
  41.  
  42.     int cCount,sCount,nCount = 0;
  43.  
  44.     //Username Creation
  45.     while(true){
  46.         printf("Enter a username: ");
  47.         scanf("%s",username);
  48.  
  49.         for(i = 0;i < 10; i++) {
  50.             taken = false;
  51.             if (strcmp(a[i].Username,username) == 0) {
  52.                 taken = true;
  53.                 break;
  54.             }
  55.         }
  56.  
  57.         if(taken == true){
  58.             printf("Username already taken! Please try a different one!\n");
  59.             continue;
  60.         }
  61.  
  62.         for(i = 0;i < 10; i++) {
  63.             if (a[i].Username != 0){
  64.                 continue;
  65.             }
  66.  
  67.             else{
  68.                 strcpy(a[i].Username,username);
  69.                 break;
  70.             }
  71.         }
  72.         break;
  73.     }
  74.  
  75.     //Password creation
  76.     while(true) {
  77.  
  78.         int j;
  79.         char tempPass[100];
  80.  
  81.         printf("Enter a password (Must contain at least one uppercase, number, and symbol): ");
  82.         scanf("%s", password);
  83.         printf("Confirm your password: ");
  84.         scanf("%s", tempPass);
  85.         //Pass check
  86.         if (strcmp(password,tempPass) != 0) {
  87.             printf("Passwords do not match!\n");
  88.             continue;
  89.         }
  90.  
  91.         if (strlen(password) < MIN) {
  92.             printf("Password is too short! Must be at least 8 characters.\n");
  93.             continue;
  94.         }
  95.  
  96.         for (j = 0; password[j] != '\0'; j++) {
  97.             if (password[j] >= 'a' && password[j] <= 'z')
  98.                 continue;
  99.  
  100.             else if (password[j] >= 'A' && password[j] <= 'Z') {
  101.                 cCount++;
  102.                 continue;
  103.             } else if (password[j] >= '0' && password[j] <= '9') {
  104.                 nCount++;
  105.                 continue;
  106.             } else {
  107.                 sCount++;
  108.                 continue;
  109.             }
  110.         }
  111.         if (cCount >= 1 && nCount >= 1 && sCount >= 1) {
  112.             break;
  113.         } else {
  114.             printf("Password does not meet the specified criteria.\n");
  115.             continue;
  116.         }
  117.     }
  118.     strcpy(a[i].Password,password);
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement