-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (61 loc) · 1.77 KB
/
main.cpp
File metadata and controls
66 lines (61 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#define max_length 256;
#define max_pass 100;
void showMenu(){
printf("╔════════════════════════════════╗\n");
printf("║ 🔐 Password generator v1.0 ║\n");
printf("╚════════════════════════════════╝\n\n");
printf(" 1. Generate password\n 2. Exit\n");
}
void genpass(char* output, int length) {
const char charset[] = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789"
"!@#$%^&*()_+-=";
int charset_size = sizeof(charset) - 1;
for (int i = 0; i < length; i++) {
int index = rand() % charset_size;
output[i] = charset[index];
}
output[length] = '\0';
}
void show_generated_password(){
char password[256];
int length;
printf("Password length (8-64): ");
if (scanf("%d", &length) != 1) {
printf("Incorrect input!\n");
while (getchar() != '\n')
;
return;
}
while (getchar() != '\n');
if (length < 8 || length > 64) {
printf("Incorrect length!\n");
return;
}
genpass(password, length);
printf("\n🔑 Generated password: %s\n", password);
}
int option = 0;
int main(){
int choice;
while (1) {
showMenu();
scanf("%d", &choice);
getchar();
switch (choice) {
case 1:
show_generated_password();
break;
case 2:
printf("\n👋 Bye-bye!\n");
return 0;
default:
printf("Incorrect option!\n");
}
}
}