TukoVPN

initialProj

Nov 22nd, 2021 (edited)
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.72 KB | None | 0 0
  1. //GROUP 1 INITIAL PROJECT
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <ctype.h>
  7. #include <stdbool.h>
  8. #include <time.h>
  9.  
  10. void login();
  11. void mainMenu();
  12. void encryptText();
  13. void decryptText();
  14. void passwordChecker();
  15. void passwordGenerator();
  16. int main(){
  17.     login();
  18.     return 0;
  19. }
  20. void login(){
  21.     system("cls");
  22.     char originalUsername[50] = "Qovthy";
  23.     char originalPassword[50] = "iluqv";
  24.     char userName[50];
  25.     char password[50];
  26.  
  27.     int usernameResult,passwordResult;
  28.  
  29.     printf("\n\tLogin System\n");
  30.     fflush(stdin);
  31.     printf("\tEnter Username: ");
  32.     scanf("%[^\n]s", &userName);
  33.     fflush(stdin);
  34.     printf("\tEnter Password: ");
  35.     scanf("%[^\n]s", &password);
  36.  
  37.     for(int i = 0;i < strlen(originalUsername); i++){
  38.         originalUsername[i] = originalUsername[i] - 7;
  39.     }
  40.     for(int i = 0;i < strlen(originalPassword); i++){
  41.         originalPassword[i] = originalPassword[i] - 8;
  42.     }
  43.     usernameResult = strcmp(userName, originalUsername);
  44.     passwordResult = strcmp(password, originalPassword);
  45.  
  46.     if (usernameResult==0){
  47.         if (passwordResult==0){
  48.             printf("\n\tLogged in, press any key to continue...");
  49.             getch();;
  50.             mainMenu();
  51.         } else {
  52.             printf("\n\tInvalid Password, press any key to try again...");
  53.             getch();
  54.             login();
  55.         }
  56.     } else {
  57.         if (passwordResult==0){
  58.             printf("\n\tInvalid Username, press any key to try again...");
  59.         } else {
  60.             printf("\n\tInvalid Username and Password, press any key to try again...");
  61.         }
  62.         getch();
  63.         login();
  64.     }
  65. }
  66. void encryptText(char text[100], int password){
  67.     int choice;
  68.     for(int i = 0;i < strlen(text); i++){
  69.         text[i] = text[i] + password;
  70.     }
  71.     printf("\n\tEncrypted string: %s\n", text);
  72.     printf("\n\tPress any key to go back in Main menu...");
  73.     getch();
  74.     mainMenu();
  75. }
  76. void decryptText(char text[100], int password){
  77.     int choice;
  78.     for(int i = 0;i < strlen(text); i++){
  79.         text[i] = text[i] - password;
  80.     }
  81.     printf("\n\tDecrypted string: %s\n", text);
  82.     printf("\n\tPress any key to go back in Main menu...");
  83.     getch();
  84.     mainMenu();
  85. }
  86. void passwordGenerator(){
  87.     int ch;
  88.     srand (time (NULL));
  89.     char alp[]  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  90.     char num[] = "0123456789";
  91.     char sym[] = "`~!@#$%^&*()_-+={}[]\\|:;\"'<>,.?/";
  92.     char password[50];
  93.     int x = 0, y = 0, z = 0;
  94.  
  95.     printf ("\n\tYour Password: ");
  96.  
  97.     for (int i = 0; i < 3; i++){
  98.         x = (rand () % 51) + 1;
  99.         y = (rand () % 9) + 1;
  100.         z = (rand () % 31) + 1;
  101.         printf ("%c%c%c", alp[x], num[y], sym[z]);
  102.     }
  103.     printf("\n\tPress any key to go back in Main menu...");
  104.     getch();
  105.     mainMenu();
  106. }
  107. void passwordChecker(){
  108.     char string1[100];
  109.     char vw[25] = "Very Weak";
  110.     char w[25] = "Weak";
  111.     char s[25] = "Strong";
  112.     printf("\n\tEnter Password to check: ");
  113.     scanf("%[^\n]s", &string1);
  114.  
  115.     bool hasUpper = false;
  116.     bool hasLower = false;
  117.     bool hasDigit = false;
  118.  
  119.     for(int i =0; i < strlen(string1); ++i){
  120.         if( islower(string1[i]) ){
  121.             hasLower = true;
  122.         }
  123.         if( isupper(string1[i]) ){
  124.             hasUpper = true;
  125.         }
  126.         if( isdigit(string1[i]) ){
  127.  
  128.             hasDigit = true;
  129.         }
  130.     }
  131.     if (strlen(string1) > 8) {
  132.         if(hasLower && hasUpper && hasDigit){
  133.             printf("\n\tPassword classification: %s Password", s);
  134.             printf("\n\tIt contains combination of lowercase, uppercase, and number\n");
  135.             printf("\n\tPress any key to go back in Main menu...");
  136.             getch();
  137.             mainMenu();
  138.         } else if (hasLower && hasUpper) {
  139.             printf("\n\tPassword classification: %s Password", w);
  140.             printf("\n\tPlease add numbers\n");
  141.             printf("\n\tPress any key to go back in Main menu...");
  142.             getch();
  143.             mainMenu();
  144.         } else if (hasLower && hasDigit) {
  145.             printf("\n\tPassword classification: %s Password", w);
  146.             printf("\n\tPlease add uppercase\n");
  147.             printf("\n\tPress any key to go back in Main menu...");
  148.             getch();
  149.             mainMenu();
  150.         } else if (hasUpper && hasDigit) {
  151.             printf("\n\tPassword classification: %s Password", w);
  152.             printf("\n\tPlease add uppercase\n");
  153.             printf("\n\tPress any key to go back in Main menu...");
  154.             getch();
  155.             mainMenu();
  156.         } else if (hasLower) {
  157.             printf("\n\tPassword classification: %s Password", vw);
  158.             printf("\n\tPlease add uppercase, and number\n");
  159.             printf("\n\tPress any key to go back in Main menu...");
  160.             getch();
  161.             mainMenu();
  162.         } else if (hasUpper) {
  163.             printf("\n\tPassword classification: %s Password", vw);
  164.             printf("\n\tPlease add lowercase, and number\n");
  165.             printf("\n\tPress any key to go back in Main menu...");
  166.             getch();
  167.             mainMenu();
  168.         } else if (hasDigit) {
  169.             printf("\n\tPassword classification: %s Password", vw);
  170.             printf("\n\tPlease add lowercase, and uppercase\n");
  171.             printf("\n\tPress any key to go back in Main menu...");
  172.             getch();
  173.             mainMenu();
  174.         }
  175.     } else {
  176.         printf("\n\tYour password is not safe it must be 8 or more characters\n");
  177.         printf("\n\tPress any key to go back in Main menu...");
  178.         getch();
  179.         mainMenu();
  180.     }
  181. }
  182. void mainMenu(){
  183.     system("cls");
  184.     int option;
  185.     char text[100];
  186.     int password;
  187.  
  188.     printf("\n\tMain menu:\n");
  189.     printf("\t[1]. Encrypt the string.\n");
  190.     printf("\t[2]. Decrypt the string.\n");
  191.     printf("\t[3]. Password generator.\n");
  192.     printf("\t[4]. Password checker.\n");
  193.     printf("\tEnter option: ");
  194.     scanf("%d", &option);
  195.  
  196.     switch(option){
  197.     case 1:
  198.         fflush(stdin);
  199.         printf("\n\tPlease enter a string:\t");
  200.         gets(text);
  201.         printf("\tEnter password (ex. 123):");
  202.         scanf("%d", &password);
  203.         encryptText(text, password);
  204.         break;
  205.     case 2:
  206.         fflush(stdin);
  207.         printf("\n\tPlease enter a string:\t");
  208.         gets(text);
  209.         printf("\tEnter password (ex. 123):");
  210.         scanf("%d", &password);
  211.         decryptText(text, password);
  212.         break;
  213.     case 3:
  214.         fflush(stdin);
  215.         passwordGenerator();
  216.         break;
  217.     case 4:
  218.         fflush(stdin);
  219.         passwordChecker();
  220.         break;
  221.     default:
  222.         printf("\nError\n");
  223.     }
  224. }
  225.  
Add Comment
Please, Sign In to add comment