-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCryptoLock.java
More file actions
59 lines (52 loc) · 1.88 KB
/
CryptoLock.java
File metadata and controls
59 lines (52 loc) · 1.88 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
import java.util.*;
class CryptoLock {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Auth myAuth = new Auth();
while (true) {
System.out.println("1. Register\n2. Login\n3. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
registerUser(scanner);
break;
case 2:
loginUser(scanner);
break;
case 3:
System.out.println("Exiting...");
System.exit(0);
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
static void registerUser(Scanner scanner) {
System.out.print("Enter username: ");
String username = scanner.nextLine();
System.out.print("Enter displayname: ");
String displayName = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();
System.out.print("Confirm password: ");
String confirmPassword = scanner.nextLine();
if (Auth.checkPasswordMatching(password, confirmPassword)) {
Auth.registerUser(username, displayName, password);
} else {
System.out.println("Passwords do not match.");
}
}
static void loginUser(Scanner scanner) {
System.out.print("Enter username: ");
String username = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();
if (Auth.loginUser(username, password)) {
System.out.println("Login successful!");
} else {
System.out.println("Login failed.");
}
}
}