-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSource.cpp
156 lines (155 loc) · 2.88 KB
/
Source.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include<iostream>
#include<string>
#include<stdlib.h>
#include<time.h>
using namespace std;
class pass_gen{
string password,Ualpha,Lalpha,spec_char,num;
int passLength,choice;
char inc;
bool Ualph,Lalph,special,numb;
public:
pass_gen():password(""),Ualpha("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),Lalpha("abcdefghijklmnopqrstuvwxyz"),spec_char("@#$%&*"),num("0123456789"),
Ualph(true),Lalph(true),special(true),numb(true),inc(' '){}
void setter();
void passwordGenerator();
void getter() const;
};
void pass_gen::setter(){
while(1){
cout<<"enter the length of password (min 7 & max 100): ";
cin>>passLength;
if(passLength<7 || passLength>100)
cout<<"length must be greater than or equal to 7 and less than or equal to 100!!!";
else
break;
}
while(1){
while(1){
cout<<"wanna include Uppercase alphabets? 'y' for yes and 'n' for no: ";
cin>>inc;
if(inc == 'y' || inc == 'Y'){
Ualph=true;
break;
}
else if(inc == 'n' || inc == 'N'){
Ualph=false;
break;
}
else
cout<<"invalid choice!!!";
}
while(1){
cout<<"wanna include Lowercase alphabets? 'y' for yes and 'n' for no: ";
cin>>inc;
if(inc == 'y' || inc == 'Y'){
Lalph=true;
break;
}
else if(inc == 'n' || inc == 'N'){
Lalph=false;
break;
}
else
cout<<"invalid choice!!!";
}
while(1){
cout<<"wanna include Numbers? 'y' for yes and 'n' for no: ";
cin>>inc;
if(inc == 'y' || inc == 'Y'){
numb=true;
break;
}
else if(inc == 'n' || inc == 'N'){
numb=false;
break;
}
else
cout<<"invalid choice!!!";
}
while(1){
cout<<"wanna include Special characters? 'y' for yes and 'n' for no: ";
cin>>inc;
if(inc == 'y' || inc == 'Y'){
special=true;
break;
}
else if(inc == 'n' || inc == 'N'){
special=false;
break;
}
else
cout<<"invalid choice!!!";
}
if(Ualph == false && Lalph == false && special == false && numb == false)
cout<<"you must include at least one thing!!!!";
else
break;
}
}
void pass_gen::passwordGenerator(){
srand(time(NULL));
for(int i=0;i<passLength;i++){
choice=rand()%4 + 1;
switch(choice){
case 1:
{
if(Ualph == true){
choice=rand()%26;
password=password+Ualpha[choice];
break;
}
else
i--;
break;
}
case 2:
{
if(Lalph == true){
choice=rand()%26;
password=password+Lalpha[choice];
break;
}
else
i--;
break;
}
case 3:
{
if(special == true){
choice=rand()%6;
password=password+spec_char[choice];
break;
}
else
i--;
break;
}
case 4:
{
if(numb == true){
choice=rand()%10;
password=password+num[choice];
break;
}
else
i--;
break;
}
default:
break;
}
}
}
void pass_gen::getter() const{
cout<<"password: "<<password<<endl;
}
int main()
{
pass_gen obj;
obj.setter();
obj.passwordGenerator();
obj.getter();
system("pause");
return 0;
}