-
-
Save coresh/1ed9ca50433ce7b885780ae946264a4e to your computer and use it in GitHub Desktop.
Password Generator Using C Language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <time.h> | |
| #include <stdlib.h> | |
| char passwordType[1]; | |
| int generateRandomNumbers(); | |
| char password[512]; | |
| char passwordLength[]; | |
| void printPassword(); | |
| int main() { | |
| srand(time(NULL)); | |
| printf("Welcome To Password Generator 2018\n"); | |
| printf("You can generate any kind of password you would like to...\n"); | |
| printf("Choose one of type below , you can choose both or triple too\n"); | |
| printf("a) a to z \nb) A to Z \nc) 0 to 9 \nd) special characters only\ne) anything\nf) a & b\ng) a & c\n" | |
| "h) a & d \ni) b & c \nj) b & d\nk) c & d\nl) a, b & c\nm) b, c & d\nn) a,c, &d " | |
| "\no)a,b &d\np)a,b,c &d\n"); | |
| printf("Enter any type given above(recommended == e)\n"); | |
| gets(passwordType); | |
| printf("Enter the password length\n"); | |
| gets(passwordLength); | |
| printPassword(); | |
| char isAgain[1]; | |
| printf("Do you want to generate password again(y/n)\n"); | |
| gets(isAgain); | |
| if (isAgain[0] == 'y'){ | |
| main(); | |
| } else if (isAgain[0] == 'n'){ | |
| printf("Thanks for using my password generator\n"); | |
| } else{ | |
| printf("Invalid input\n"); | |
| } | |
| return 0; | |
| } | |
| int generateRandomNumbers(){ | |
| int random; | |
| int r; | |
| switch (passwordType[0]){ | |
| case 'a': | |
| random = (rand() % (122 + 1 - 97)) + 97; | |
| break; | |
| case 'b': | |
| random = (rand() % (90 + 1 - 65)) + 65; | |
| break; | |
| case 'c': | |
| random = (rand() % (57 + 1 - 48)) + 48; | |
| break; | |
| case 'd': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if (((r<=47) && (r>=33)) || ((r<=64) && (r>=58)) || ((r<=96) && (r>=91)) || ((r<=175) && (r>=123)) || ((r<=254) && (r>=178))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'e': | |
| random = (rand() % (126 + 1 - 33)) + 33; | |
| break; | |
| case 'f': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if (((r<=90) && (r>=65)) || ((r<=122) && (r>=97))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'g': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if (((r<=57) && (r>=48)) || ((r<=122) && (r>=97))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'h': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if (((r<=122) && (r>=97)) ||((r<=47) && (r>=33)) || ((r<=64) && (r>=58)) || ((r<=96) && (r>=91)) || ((r<=175) && (r>=123)) || ((r<=254) && (r>=178))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'i': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if (((r<=90) && (r>=65)) || ((r<=57) && (r>=48))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'j': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if (((r<=90) && (r>=65)) ||((r<=47) && (r>=33)) || ((r<=64) && (r>=58)) || ((r<=96) && (r>=91)) || ((r<=175) && (r>=123)) || ((r<=254) && (r>=178))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'k': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if (((r<=57) && (r>=48)) || ((r<=47) && (r>=33)) || ((r<=64) && (r>=58)) || ((r<=96) && (r>=91)) || ((r<=175) && (r>=123)) || ((r<=254) && (r>=178))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'l': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if(((r<=122) && (r>=97)) || ((r<=90) && (r>=65)) || ((r<=57) && (r>=48))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'm': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if(((r<=90) && (r>=65)) || ((r<=57) && (r>=48)) || ((r<=47) && (r>=33)) || ((r<=64) && (r>=58)) || ((r<=96) && (r>=91)) || ((r<=175) && (r>=123)) || ((r<=254) && (r>=178))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'n': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if(((r<=122) && (r>=97)) || ((r<=57) && (r>=48)) || ((r<=47) && (r>=33)) || ((r<=64) && (r>=58)) || ((r<=96) && (r>=91)) || ((r<=175) && (r>=123)) || ((r<=254) && (r>=178))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'o': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if(((r<=122) && (r>=97)) || ((r<=90) && (r>=65)) || ((r<=47) && (r>=33)) || ((r<=64) && (r>=58)) || ((r<=96) && (r>=91)) || ((r<=175) && (r>=123)) || ((r<=254) && (r>=178))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| case 'p': | |
| while (1){ | |
| r = (rand() % (256 + 1 - 0)) + 0; | |
| if(((r<=122) && (r>=97)) || ((r<=90) && (r>=65)) || ((r<=57) && (r>=48)) || ((r<=47) && (r>=33)) || ((r<=64) && (r>=58)) || ((r<=96) && (r>=91)) || ((r<=175) && (r>=123)) || ((r<=254) && (r>=178))){ | |
| random = r; | |
| break; | |
| } | |
| } | |
| break; | |
| default: | |
| printf("Invalid Input so we are exiting you from program and starting again\n"); | |
| main(); | |
| } | |
| return random; | |
| } | |
| void printPassword(){ | |
| int randomNumber; | |
| int k; | |
| int length = atoi(passwordLength); | |
| for (k = 0; k < length; k++) { | |
| randomNumber = generateRandomNumbers(); | |
| password[k] = randomNumber; | |
| } | |
| for (int j = 0; j < length+19; j++) { | |
| printf("="); | |
| } | |
| printf("\n"); | |
| printf("Your password is: %s", password); | |
| printf("\n"); | |
| for (int a = 0; a < length+19; a++) { | |
| printf("="); | |
| } | |
| printf("\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment