-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordManagerData.java
More file actions
300 lines (299 loc) · 9.79 KB
/
PasswordManagerData.java
File metadata and controls
300 lines (299 loc) · 9.79 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import java.util.*;
class PasswordManagerData
{
String Username;
String Web_Data;
String New_Website_Name;
String Password_Data;
String New_Password;
}
class PasswordManager extends PasswordManagerData
{
void Get()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter Website Name: ");
Web_Data = sc.nextLine();
boolean Valid_Password=false;
do
{
System.out.print("Enter Password: ");
Password_Data = sc.nextLine();
Valid_Password = true;
if (Password_Data.length() < 8)
{
System.out.println("Your Password Must Have Atleast 8 Characters ");
Valid_Password = false;
}
if (Password_Data.equals(Username))
{
System.out.println("Your Password Must Not Be Same As The User Name You Entered ");
Valid_Password = false;
}
boolean UpperCase = false;
boolean LowerCase = false;
boolean Digits = false;
for (int i = 0; i < Password_Data.length(); i++)
{
char c = Password_Data.charAt(i);
if (c >= 'A' && c <= 'Z')
{
UpperCase = true;
}
if (c >= 'a' && c <= 'z')
{
LowerCase = true;
}
if (c >= '0' && c <= '9')
{
Digits = true;
}
}
if (!UpperCase)
{
System.out.println("Your Password Must Have Atleast 1 Capital Letter");
Valid_Password = false;
}
if (!LowerCase)
{
System.out.println("Your Password Must Have Atleast 1 Small Letter");
Valid_Password = false;
}
if (!Digits)
{
System.out.println("Your Password Must Have Atleast one Integral Number");
Valid_Password = false;
}
} while (!Valid_Password);
}
void CheckPassword(String s)
{
Scanner sc = new Scanner(System.in);
boolean flag = true;
while (flag)
{
System.out.print("Enter Your Email ID's Password to Access Your Saved Passwords : ");
String x = sc.nextLine();
if (x.equals(s))
{
flag = false;
} else
{
System.out.println("Enter Correct Password ");
}
}
}
int Search(PasswordManager[] a)
{
Scanner sc = new Scanner(System.in);
for (int i = 0; i < a.length; i++)
{
System.out.println((i + 1) + " " + a[i].Web_Data);
}
System.out.print("Enter the Number of Corresponding To Your Desired Website : ");
return sc.nextInt();
}
void Display(int n, PasswordManager[] a)
{
System.out.println("Website : " + a[n - 1].Web_Data);
System.out.println("Password : " + a[n - 1].Password_Data);
}
void Display_Array(PasswordManager[] a)
{
for (int i = 0; i < a.length; i++)
{
System.out.println("Website : " + a[i].Web_Data);
System.out.println("Password : " + a[i].Password_Data);
}
}
void EditPassword(PasswordManager[] a)
{
Scanner sc = new Scanner(System.in);
for (int i = 0; i < a.length; i++)
{
System.out.println((i + 1) + ". " + a[i].Web_Data);
}
System.out.print("Enter the Index Shown Above which you desire to change : ");
int n = sc.nextInt();
boolean flag = true;
while (flag)
{
System.out.print("Enter your Old Password : ");
String Old_Password = sc.nextLine();
if (a[n - 1].Password_Data.equals(Old_Password))
{
System.out.print("Enter the New Password : ");
New_Password = sc.nextLine();
flag = false;
}
else
{
System.out.println("Incorrect Password");
}
}
a[n - 1].Password_Data = New_Password;
System.out.println("Password Updated Successfully ");
System.out.println("Website : "+a[n-1].Web_Data);
System.out.println("Updated Password : " + a[n - 1].Password_Data);
}
PasswordManager[] Delete(PasswordManager[] PM)
{
Scanner sc = new Scanner(System.in);
for (int i = 0; i < PM.length; i++)
{
System.out.println((i + 1) + ". " + PM[i].Web_Data);
}
System.out.print("Enter the index number of the website whose password you want to delete : ");
int n = sc.nextInt();
if (n < 1 || n > PM.length)
{
System.out.println("Invalid index number entered!");
return PM;
}
PasswordManager[] newPM = new PasswordManager[PM.length - 1];
int j = 0;
for (int i = 0; i < PM.length; i++)
{
if ((n - 1) != i)
{
newPM[j] = PM[i];
j++;
}
}
System.out.println("Website password deleted successfully!");
return newPM;
}
PasswordManager[] AddPasswords(PasswordManager[] a)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter The Number of Passwords to Add in Your Database : ");
int New_Array_Length = sc.nextInt();
PasswordManager[] a1 = new PasswordManager[a.length + New_Array_Length];
for (int i = a.length; i < a1.length; i++)
{
a1[i] = new PasswordManager();
a1[i].Get();
}
for(int i=0;i<a.length;i++)
{
a1[i]=a[i];
}
System.out.println("Password added successfully ");
return a1;
}
void EditWebsiteName(PasswordManager[] a)
{
Scanner sc = new Scanner(System.in);
for (int i = 0; i < a.length; i++)
{
System.out.println((i + 1) + ". " + a[i].Web_Data);
}
System.out.print("Enter the Index Shown Above which you desire to change : ");
int n = sc.nextInt();
sc.nextLine();
if (n >= 1 && n <= a.length)
{
System.out.println("Current Website Name is "+a[n-1].Web_Data);
System.out.print("Enter The New Website Name : ");
New_Website_Name=sc.nextLine();
a[n-1].Web_Data = New_Website_Name;
System.out.println("Website Name Changed Successfully ");
}
else
{
System.out.println("Invalid index entered.");
}
}
}
class Run
{
static
{
System.out.println("-------------------Personalized Access Control for Passwords---------------------");
System.out.println(" Welcome to Your Personal Password Manager ");
}
public static void main(String[] args)
{
String EPassword;
Scanner sc = new Scanner(System.in);
System.out.println();
System.out.println();
PasswordManager a = new PasswordManager();
System.out.print("Enter Your E-Mail ID : ");
String EMail = sc.nextLine();
System.out.print("Enter Your Username : ");
a.Username=sc.nextLine();
System.out.print("Enter Your E-Mail ID's Password : ");
EPassword = sc.nextLine();
System.out.print("Enter The Number of Website Whose Passwords You Want to Manage : ");
int Array_Length = sc.nextInt();
PasswordManager[] PM = new PasswordManager[Array_Length];
for (int i = 0; i < PM.length; i++)
{
PM[i] = new PasswordManager();
PM[i].Get();
}
int Operations = 0;
char ch = 'y';
while (ch == 'y' || ch == 'Y')
{
System.out.println("Enter The Number Displayed Below Corresponding to Your Desired Operation ");
System.out.println("1. Add More Passwords ");
System.out.println("2. Edit The Existing Passwords ");
System.out.println("3. Delete The Existing Passwords ");
System.out.println("4. To Search For The Specific Website's Password");
System.out.println("5. Display the Existing Passwords");
System.out.println("6. Exit");
Operations = sc.nextInt();
switch (Operations)
{
case 1:
a.CheckPassword(EPassword);
PM=a.AddPasswords(PM);
break;
case 2:
System.out.println("Enter W for Website , P for Password Edit and B for Both ");
System.out.print("Do You Want To Edit Website's Name or Password or Both : ");
char ch1=sc.next().charAt(0);
if(ch1=='W'||ch1=='w')
{
a.CheckPassword(EPassword);
a.EditWebsiteName(PM);
}
if(ch1=='P'||ch1=='p')
{
a.CheckPassword(EPassword);
a.EditPassword(PM);
}
if(ch1=='B'||ch1=='b')
{
a.CheckPassword(EPassword);
a.EditWebsiteName(PM);
a.EditPassword(PM);
}
else
{
System.out.println("Please Enter a Correct Response ");
}
break;
case 3:
a.CheckPassword(EPassword);
PM = a.Delete(PM);
break;
case 4:
a.CheckPassword(EPassword);
a.Display(a.Search(PM), PM);
break;
case 5:
a.CheckPassword(EPassword);
a.Display_Array(PM);
break;
case 6:
System.out.println("Thanks for Visiting");
System.exit(0);
default:
System.out.println("Invalid Number Entered. Please try again.");
}
}
}
}