-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
70 lines (58 loc) · 2.13 KB
/
Main.java
File metadata and controls
70 lines (58 loc) · 2.13 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int option = 0;
while(option!=3){
System.out.println("\n\n====Java Passwords Manager====");
System.out.println("1. Generate New Password ");
System.out.println("2. View Saved Passwords ");
System.out.println("3. Exit Program..");
System.out.print("Your Option: " );
Scanner sc = new Scanner(System.in);
option = sc.nextInt();
sc.nextLine();
switch(option) {
case 1->{
clearScreen();
genPass();
}
case 2->{
clearScreen();
StoredPasswords SP = new StoredPasswords();
SP.showSavedPasswords();
}
case 3-> System.out.println("Exiting Program...");
default-> System.out.println("invalid option!");
}
}
System.out.println("Thank You!");
}
public static void genPass(){
Scanner sc = new Scanner(System.in);
System.out.println("\n===Generate new Password:===\n");
System.out.print("Website: ");
String website = sc.nextLine();
System.out.print("Email: ");
String email = sc.nextLine();
System.out.print("Pass length: ");
int len = sc.nextInt();
PassGenerator p1 = new PassGenerator(len);
String newPass = p1.generatePass();
SinglePass s1 = new SinglePass(website,email,newPass);
s1.saveSinglePass();
}
public static void clearScreen() {
try {
final String os = System.getProperty("os.name").toLowerCase();
ProcessBuilder pb;
if (os.contains("windows")) {
pb = new ProcessBuilder("cmd", "/c", "cls");
} else {
pb = new ProcessBuilder("clear");
}
pb.inheritIO().start().waitFor();
} catch (final Exception e) {
System.err.println("Error clearing console: " + e.getMessage());
}
}
}