-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpassword generator with GUI.cpp
119 lines (112 loc) · 2.33 KB
/
password generator with GUI.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include<bits/stdc++.h>
using namespace std;
int random(int limit) //Generating random number in range (limit)
{
static int x=3251;
x=((x*x)/100)%10000;
return x%limit;
}
void gen_pass(int len)
{
string pass = "";
string alpha = "qwertyuioplkjhgfdsazxcvbnm";
string Alpha = "QWERTYUIOPLKJHGFDSAZXCVBNM";
string spchar = "!@#$%&*";
string nums = "1234567890";
int count=0, acount=0, Acount=0, scount=0, ncount=0;
int temp=random(26);
pass+=alpha[temp];
acount++;
while(count<len-2)
{
int flag=random(4);
switch(flag)
{
case 0: //min 1 upper case letter
{
if((Acount==1) && (acount<2 || scount<1 || ncount<1)) //first fulfilling basic condition after then we will complete the limit of the password
break;
else
{
temp=random(26);
pass+=Alpha[temp];
count++;
Acount++;
break;
}
}
case 1: //min 2 lower case letters
{
if((acount==2) && (Acount<1 || ncount<1 || scount<1))
break;
else
{
temp=random(26);
pass+=alpha[temp];
count++;
acount++;
break;
}
}
case 2: //min 1 numeric character
{
if((ncount==1) && (Acount<1 || acount<2 || scount<1))
break;
else
{
temp=random(10);
pass+=nums[temp];
count++;
ncount++;
break;
}
}
case 3: //min 1 special character
{
if((scount==1) && (Acount<1 || acount<2 || ncount<1))
break;
else
{
temp=random(7);
pass+=spchar[temp];
count++;
scount++;
break;
}
}
}
}
temp=random(26); //ending with Upper Case
pass+=Alpha[temp];
cout<<endl<<"Password Generated: "<<pass<<endl; //final password
system("PAUSE");
system("cls");
}
int main()
{
int op, len;
system("cls");
do{
cout<<"1. Generate Password"<<endl;
cout<<"2. Exit"<<endl;
cin>>op;
if(op==1)
{
cout << "\n\tEnter Required Length: ";
cin >> len;
if(len < 12 || len > 32){ // required length parameters check
cout << "\n\t\tERROR!!\n\t(Password should contain at least 6 characters and at max 32 characters) \n\t";
system("PAUSE");
system("cls");
}
else
gen_pass(len); // function call
}
else if(op!=1 && op!=2)
{
cout<<"Invalid Input"<<endl;
system("PAUSE");
system("cls");
}
}while(op!=2);
}