-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordAddScreen.java
More file actions
71 lines (55 loc) · 2.48 KB
/
Copy pathPasswordAddScreen.java
File metadata and controls
71 lines (55 loc) · 2.48 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
import javax.swing.*;
import java.awt.*;
public class PasswordAddScreen {
private JPanel panel;
private SecurePassManager app;
private PasswordVault vault;
private UserDashboard dashboard;
public PasswordAddScreen(SecurePassManager app, PasswordVault vault, UserDashboard dashboard) {
this.app = app;
this.vault = vault;
this.dashboard = dashboard;
panel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(10, 10, 10, 10);
c.fill = GridBagConstraints.HORIZONTAL;
JTextField siteField = new JTextField(25);
JTextField userField = new JTextField(25);
JPasswordField passField = new JPasswordField(25);
JTextField notesField = new JTextField(25);
c.gridx = 0; c.gridy = 0; panel.add(new JLabel("Site/App:"), c);
c.gridx = 1; panel.add(siteField, c);
c.gridx = 0; c.gridy++; panel.add(new JLabel("Username/Email:"), c);
c.gridx = 1; panel.add(userField, c);
c.gridx = 0; c.gridy++; panel.add(new JLabel("Password:"), c);
c.gridx = 1; panel.add(passField, c);
c.gridx = 0; c.gridy++; panel.add(new JLabel("Notes:"), c);
c.gridx = 1; panel.add(notesField, c);
JButton saveBtn = new JButton("Save");
JButton cancelBtn = new JButton("Cancel");
c.gridx = 0; c.gridy++; c.gridwidth = 2;
JPanel btns = new JPanel();
btns.add(cancelBtn);
btns.add(saveBtn);
panel.add(btns, c);
saveBtn.addActionListener(e -> {
String site = siteField.getText().trim();
String user = userField.getText().trim();
String pass = new String(passField.getPassword());
String notes = notesField.getText();
if (site.isEmpty() || pass.isEmpty()) {
JOptionPane.showMessageDialog(panel, "Site and Password required!");
return;
}
PasswordEntry entry = new PasswordEntry(site, user, Encoder.encode(pass), notes);
vault.addEntry(entry);
vault.saveToFile(app.getCurrentUser());
LogManager.log(app.getCurrentUser(), "Added password for " + site);
JOptionPane.showMessageDialog(panel, "Password saved!");
dashboard.refresh();
app.showScreen("Dashboard");
});
cancelBtn.addActionListener(e -> app.showScreen("Dashboard"));
}
public JPanel getPanel() { return panel; }
}