Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <string.h>
  5.  
  6. #define MIN 8
  7.  
  8. struct ACCOUNTS {
  9.     char Username[100];
  10.     char Password[100];
  11.     float Balance;
  12. } a[10] = {0};
  13.  
  14. void logMenu();
  15. void accCreate();
  16. int logIn();
  17.  
  18. int logIn(){
  19.  
  20.     char uName[100], uPass[100];
  21.     int i, j;
  22.     bool exists = false;
  23.  
  24.     while(true) {
  25.         printf("Username: ");
  26.         scanf("%s", uName);
  27.  
  28.         for (i = 0; i < 10; i++) {
  29.             exists = false;
  30.             if(strcmp(a[i].Username,uName) == 0){
  31.                 exists = true;
  32.                 j = i;
  33.                 break;
  34.             }
  35.         }
  36.  
  37.         if(exists = true){
  38.             printf("Password: ");
  39.             scanf("%s",uPass);
  40.  
  41.             if(strcmp(a[i].Password,uPass) == 0){
  42.                 printf("Success!");
  43.                 return j;
  44.             }
  45.  
  46.             else{
  47.                 printf("Account doesn't exist or the password is wrong! Try again.");
  48.                 continue;
  49.             }
  50.         }
  51.     }
  52. }
  53.  
  54. void accCreate(){
  55.     char username[100], password[100];
  56.     int i;
  57.     bool taken;
  58.  
  59.     int cCount,sCount,nCount = 0;
  60.  
  61.     //Username Creation
  62.     while(true){
  63.         printf("Enter a username: ");
  64.         scanf("%s",username);
  65.  
  66.         for(i = 0;i < 10; i++) {
  67.             taken = false;
  68.             if (strcmp(a[i].Username,username) == 0) {
  69.                 taken = true;
  70.                 break;
  71.             }
  72.         }
  73.  
  74.         if(taken == true){
  75.             printf("Username already taken! Please try a different one!\n");
  76.             continue;
  77.         }
  78.  
  79.         for(i = 0;i < 10; i++) {
  80.             if (a[i].Username != 0){
  81.                 continue;
  82.             }
  83.  
  84.             else{
  85.                 strcpy(a[i].Username,username);
  86.                 break;
  87.             }
  88.         }
  89.         break;
  90.     }
  91.  
  92.     //Password creation
  93.     while(true) {
  94.  
  95.         int j;
  96.         char tempPass[100];
  97.  
  98.         printf("Enter a password (Must contain at least one uppercase, number, and symbol): ");
  99.         scanf("%s", password);
  100.         printf("Confirm your password: ");
  101.         scanf("%s", tempPass);
  102.         //Pass check
  103.         if (strcmp(password,tempPass) != 0) {
  104.             printf("Passwords do not match!\n");
  105.             continue;
  106.         }
  107.  
  108.         if (strlen(password) < MIN) {
  109.             printf("Password is too short! Must be at least 8 characters.\n");
  110.             continue;
  111.         }
  112.  
  113.         for (j = 0; password[j] != '\0'; j++) {
  114.             if (password[j] >= 'a' && password[j] <= 'z')
  115.                 continue;
  116.  
  117.             else if (password[j] >= 'A' && password[j] <= 'Z') {
  118.                 cCount++;
  119.                 continue;
  120.             } else if (password[j] >= '0' && password[j] <= '9') {
  121.                 nCount++;
  122.                 continue;
  123.             } else {
  124.                 sCount++;
  125.                 continue;
  126.             }
  127.         }
  128.         if (cCount >= 1 && nCount >= 1 && sCount >= 1) {
  129.             break;
  130.         } else {
  131.             printf("Password does not meet the specified criteria.\n");
  132.             continue;
  133.         }
  134.     }
  135.     strcpy(a[i].Password,password);
  136. }
  137.  
  138. void logMenu(){
  139.     while(true) {
  140.  
  141.         int choice;
  142.         int mCont;
  143.  
  144.         system("cls");
  145.         printf("1. Log In\n");
  146.         printf("2. Create Account\n");
  147.         printf("3. Exit\n");
  148.  
  149.         scanf("%d",&choice);
  150.  
  151.         if(choice == 1){
  152.             logIn();
  153.         }
  154.  
  155.         else if(choice == 2){
  156.             accCreate();
  157.         }
  158.  
  159.         else if(choice == 3){
  160.             printf("Under construction.");
  161.         }
  162.  
  163.         else{
  164.             printf("Invalid option. Please try again.");
  165.         }
  166.     }
  167. }
  168.  
  169. void main(){
  170.  
  171.     logMenu();
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement