Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //GROUP 1 INITIAL PROJECT
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <stdbool.h>
- #include <time.h>
- void login();
- void mainMenu();
- void encryptText();
- void decryptText();
- void passwordChecker();
- void passwordGenerator();
- int main(){
- login();
- return 0;
- }
- void login(){
- system("cls");
- char originalUsername[50] = "Qovthy";
- char originalPassword[50] = "iluqv";
- char userName[50];
- char password[50];
- int usernameResult,passwordResult;
- printf("\n\tLogin System\n");
- fflush(stdin);
- printf("\tEnter Username: ");
- scanf("%[^\n]s", &userName);
- fflush(stdin);
- printf("\tEnter Password: ");
- scanf("%[^\n]s", &password);
- for(int i = 0;i < strlen(originalUsername); i++){
- originalUsername[i] = originalUsername[i] - 7;
- }
- for(int i = 0;i < strlen(originalPassword); i++){
- originalPassword[i] = originalPassword[i] - 8;
- }
- usernameResult = strcmp(userName, originalUsername);
- passwordResult = strcmp(password, originalPassword);
- if (usernameResult==0){
- if (passwordResult==0){
- printf("\n\tLogged in, press any key to continue...");
- getch();;
- mainMenu();
- } else {
- printf("\n\tInvalid Password, press any key to try again...");
- getch();
- login();
- }
- } else {
- if (passwordResult==0){
- printf("\n\tInvalid Username, press any key to try again...");
- } else {
- printf("\n\tInvalid Username and Password, press any key to try again...");
- }
- getch();
- login();
- }
- }
- void encryptText(char text[100], int password){
- int choice;
- for(int i = 0;i < strlen(text); i++){
- text[i] = text[i] + password;
- }
- printf("\n\tEncrypted string: %s\n", text);
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- }
- void decryptText(char text[100], int password){
- int choice;
- for(int i = 0;i < strlen(text); i++){
- text[i] = text[i] - password;
- }
- printf("\n\tDecrypted string: %s\n", text);
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- }
- void passwordGenerator(){
- int ch;
- srand (time (NULL));
- char alp[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- char num[] = "0123456789";
- char sym[] = "`~!@#$%^&*()_-+={}[]\\|:;\"'<>,.?/";
- char password[50];
- int x = 0, y = 0, z = 0;
- printf ("\n\tYour Password: ");
- for (int i = 0; i < 3; i++){
- x = (rand () % 51) + 1;
- y = (rand () % 9) + 1;
- z = (rand () % 31) + 1;
- printf ("%c%c%c", alp[x], num[y], sym[z]);
- }
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- }
- void passwordChecker(){
- char string1[100];
- char vw[25] = "Very Weak";
- char w[25] = "Weak";
- char s[25] = "Strong";
- printf("\n\tEnter Password to check: ");
- scanf("%[^\n]s", &string1);
- bool hasUpper = false;
- bool hasLower = false;
- bool hasDigit = false;
- for(int i =0; i < strlen(string1); ++i){
- if( islower(string1[i]) ){
- hasLower = true;
- }
- if( isupper(string1[i]) ){
- hasUpper = true;
- }
- if( isdigit(string1[i]) ){
- hasDigit = true;
- }
- }
- if (strlen(string1) > 8) {
- if(hasLower && hasUpper && hasDigit){
- printf("\n\tPassword classification: %s Password", s);
- printf("\n\tIt contains combination of lowercase, uppercase, and number\n");
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- } else if (hasLower && hasUpper) {
- printf("\n\tPassword classification: %s Password", w);
- printf("\n\tPlease add numbers\n");
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- } else if (hasLower && hasDigit) {
- printf("\n\tPassword classification: %s Password", w);
- printf("\n\tPlease add uppercase\n");
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- } else if (hasUpper && hasDigit) {
- printf("\n\tPassword classification: %s Password", w);
- printf("\n\tPlease add uppercase\n");
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- } else if (hasLower) {
- printf("\n\tPassword classification: %s Password", vw);
- printf("\n\tPlease add uppercase, and number\n");
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- } else if (hasUpper) {
- printf("\n\tPassword classification: %s Password", vw);
- printf("\n\tPlease add lowercase, and number\n");
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- } else if (hasDigit) {
- printf("\n\tPassword classification: %s Password", vw);
- printf("\n\tPlease add lowercase, and uppercase\n");
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- }
- } else {
- printf("\n\tYour password is not safe it must be 8 or more characters\n");
- printf("\n\tPress any key to go back in Main menu...");
- getch();
- mainMenu();
- }
- }
- void mainMenu(){
- system("cls");
- int option;
- char text[100];
- int password;
- printf("\n\tMain menu:\n");
- printf("\t[1]. Encrypt the string.\n");
- printf("\t[2]. Decrypt the string.\n");
- printf("\t[3]. Password generator.\n");
- printf("\t[4]. Password checker.\n");
- printf("\tEnter option: ");
- scanf("%d", &option);
- switch(option){
- case 1:
- fflush(stdin);
- printf("\n\tPlease enter a string:\t");
- gets(text);
- printf("\tEnter password (ex. 123):");
- scanf("%d", &password);
- encryptText(text, password);
- break;
- case 2:
- fflush(stdin);
- printf("\n\tPlease enter a string:\t");
- gets(text);
- printf("\tEnter password (ex. 123):");
- scanf("%d", &password);
- decryptText(text, password);
- break;
- case 3:
- fflush(stdin);
- passwordGenerator();
- break;
- case 4:
- fflush(stdin);
- passwordChecker();
- break;
- default:
- printf("\nError\n");
- }
- }
Add Comment
Please, Sign In to add comment