-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCryptoLockGUI.java
More file actions
96 lines (80 loc) · 3.04 KB
/
CryptoLockGUI.java
File metadata and controls
96 lines (80 loc) · 3.04 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CryptoLockGUI {
private JFrame frame;
private JPanel panel;
private JTextField usernameField, displayNameField;
private JPasswordField passwordField, confirmPasswordField;
private JButton registerButton, loginButton;
private JLabel statusLabel;
public CryptoLockGUI() {
frame = new JFrame("CryptoLock Authentication");
frame.setSize(400, 250);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel = new JPanel();
panel.setLayout(new GridLayout(6, 2, 5, 5));
JLabel usernameLabel = new JLabel("Username:");
usernameField = new JTextField();
panel.add(usernameLabel);
panel.add(usernameField);
JLabel displayNameLabel = new JLabel("Display Name:");
displayNameField = new JTextField();
panel.add(displayNameLabel);
panel.add(displayNameField);
JLabel passwordLabel = new JLabel("Password:");
passwordField = new JPasswordField();
panel.add(passwordLabel);
panel.add(passwordField);
JLabel confirmPasswordLabel = new JLabel("Confirm Password:");
confirmPasswordField = new JPasswordField();
panel.add(confirmPasswordLabel);
panel.add(confirmPasswordField);
registerButton = new JButton("Register");
registerButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
registerUser();
}
});
panel.add(registerButton);
loginButton = new JButton("Login");
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loginUser();
}
});
panel.add(loginButton);
statusLabel = new JLabel("");
panel.add(statusLabel);
frame.add(panel);
frame.setVisible(true);
}
private void registerUser() {
String username = usernameField.getText();
String displayName = displayNameField.getText();
String password = new String(passwordField.getPassword());
String confirmPassword = new String(confirmPasswordField.getPassword());
if (Auth.checkPasswordMatching(password, confirmPassword)) {
Auth.registerUser(username, displayName, password);
statusLabel.setText("Registration successful!");
} else {
statusLabel.setText("Passwords do not match.");
}
}
private void loginUser() {
String username = usernameField.getText();
String password = new String(passwordField.getPassword());
if (Auth.loginUser(username, password)) {
statusLabel.setText("Login successful!");
} else {
statusLabel.setText("Login failed.");
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new CryptoLockGUI();
}
});
}
}