Skip to content

Commit de2721a

Browse files
committed
Add Documentation Files
1 parent 130b5ab commit de2721a

11 files changed

+1250
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
2+
# EncryptionUtil.java
3+
4+
## Overview
5+
`EncryptionUtil` is a utility class that provides **AES encryption and decryption** for secure data handling. It uses a predefined symmetric key to encrypt and decrypt sensitive information.
6+
7+
---
8+
9+
## Features
10+
1. **Encryption**:
11+
- Encrypts a plain text input using the AES algorithm.
12+
- Encodes the encrypted result in Base64 for safe storage and transmission.
13+
14+
2. **Decryption**:
15+
- Decodes the Base64 input.
16+
- Decrypts the data using the AES algorithm and the predefined key.
17+
18+
3. **Symmetric Key**:
19+
- Utilizes a hardcoded 16-byte key: `1234567890123456`.
20+
- Key is compatible with AES-128 encryption.
21+
22+
---
23+
24+
## Code Structure
25+
26+
### Class Constants
27+
```java
28+
private static final String ALGORITHM = "AES";
29+
private static final byte[] KEY = "1234567890123456".getBytes();
30+
```
31+
- **ALGORITHM**: Specifies the encryption algorithm (AES).
32+
- **KEY**: A fixed 16-byte key used for both encryption and decryption.
33+
34+
---
35+
36+
### Method: `encrypt(String data)`
37+
- **Purpose**: Encrypts a plain text input using AES encryption.
38+
- **Parameters**:
39+
- `String data`: The text to encrypt.
40+
- **Returns**: A Base64-encoded encrypted string.
41+
- **Implementation**:
42+
- Initializes a `Cipher` instance for AES encryption mode.
43+
- Processes the input data and returns the Base64 string.
44+
45+
```java
46+
byte[] encryptedBytes = cipher.doFinal(data.getBytes());
47+
return Base64.getEncoder().encodeToString(encryptedBytes);
48+
```
49+
50+
---
51+
52+
### Method: `decrypt(String encryptedData)`
53+
- **Purpose**: Decrypts a Base64-encoded string back to its original form.
54+
- **Parameters**:
55+
- `String encryptedData`: The encrypted Base64 string.
56+
- **Returns**: The decrypted plain text.
57+
- **Implementation**:
58+
- Decodes the Base64 string into bytes.
59+
- Decrypts the data using AES decryption mode.
60+
61+
```java
62+
byte[] decodedBytes = Base64.getDecoder().decode(encryptedData);
63+
return new String(decryptedBytes);
64+
```
65+
66+
---
67+
68+
## Example Usage
69+
```java
70+
public static void main(String[] args) {
71+
try {
72+
String originalData = "MySecurePassword";
73+
String encryptedData = EncryptionUtil.encrypt(originalData);
74+
String decryptedData = EncryptionUtil.decrypt(encryptedData);
75+
76+
System.out.println("Original Data: " + originalData);
77+
System.out.println("Encrypted Data: " + encryptedData);
78+
System.out.println("Decrypted Data: " + decryptedData);
79+
} catch (Exception e) {
80+
e.printStackTrace();
81+
}
82+
}
83+
```
84+
85+
### Output:
86+
```
87+
Original Data: MySecurePassword
88+
Encrypted Data: <Base64 Encrypted String>
89+
Decrypted Data: MySecurePassword
90+
```
91+
92+
---
93+
94+
## Notes
95+
- The hardcoded key (`1234567890123456`) must be kept secure, as it is required for decryption.
96+
- AES encryption provides strong data protection, but avoid exposing the key or relying solely on hardcoded keys in production.
97+
- Base64 encoding ensures encrypted data can be safely stored in text-based formats.
98+
99+
---
100+
101+
## Dependencies
102+
- **Java Crypto Library** (`javax.crypto`).
103+
- **Base64 Encoder/Decoder** (`java.util.Base64`).
104+
105+
---
106+
107+
## Security Considerations
108+
- Hardcoding encryption keys is not recommended for production systems. Use a secure key management solution.
109+
- Always validate the encrypted data before processing.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
2+
# File: GeneratorPanel.java
3+
4+
## Overview
5+
`GeneratorPanel` is a Java class extending `JPanel`. It serves as the UI panel for generating secure passwords, copying them to the clipboard, and saving them. The class interacts with `PasswordManager` and uses auxiliary tools like `PasswordGenerator` and `PasswordStrengthCalculator`.
6+
7+
## Dependencies
8+
- `javax.swing.*`: For UI components (JTextField, JCheckBox, JButton, etc.).
9+
- `java.awt.*`: For layout management and styling.
10+
- `java.awt.datatransfer.StringSelection`: For clipboard functionality.
11+
- `javax.swing.event.ChangeEvent`, `ChangeListener`: For slider events.
12+
- `javax.swing.border.*`: For component styling.
13+
14+
## Fields
15+
16+
| Modifier | Type | Name | Description |
17+
|----------------|------------------------|-----------------------|--------------------------------------|
18+
| `private` | `JTextField` | `passwordField` | Displays the generated password. |
19+
| `private` | `JSlider` | `lengthSlider` | Controls the password length. |
20+
| `private` | `JLabel` | `lengthValueLabel` | Displays the current slider value. |
21+
| `private` | `JCheckBox` | `includeUppercase` | Toggle to include uppercase letters. |
22+
| `private` | `JCheckBox` | `includeLowercase` | Toggle to include lowercase letters. |
23+
| `private` | `JCheckBox` | `includeNumbers` | Toggle to include numbers. |
24+
| `private` | `JCheckBox` | `includeSymbols` | Toggle to include symbols. |
25+
| `private` | `JProgressBar` | `strengthIndicator` | Indicates the strength of the password.|
26+
| `private` | `PasswordManager` | `passwordManager` | Manages password storage. |
27+
| `private` | `Color` | `successColor` | Color for strong passwords. |
28+
| `private` | `Color` | `warningColor` | Color for medium passwords. |
29+
| `private` | `Color` | `errorColor` | Color for weak passwords. |
30+
| `private` | `Color` | `textColor` | Default text color. |
31+
32+
## Methods
33+
34+
### `GeneratorPanel(PasswordManager passwordManager)`
35+
- **Purpose**: Constructor for the `GeneratorPanel`.
36+
- **Parameters**:
37+
- `passwordManager`: Instance of `PasswordManager` for saving passwords.
38+
- **Description**: Initializes the panel, creates UI components, and sets up listeners.
39+
40+
### `private void initializeComponents()`
41+
- **Purpose**: Sets up the UI layout, components, and event listeners.
42+
- **Description**:
43+
- Creates a card-like styled UI for password generation.
44+
- Adds a password display field, length slider, and checkboxes for customization.
45+
- Provides buttons to generate, copy, and save passwords.
46+
47+
### `private void setupListeners()`
48+
- **Purpose**: Adds event listeners for the length slider and checkboxes.
49+
- **Listeners**:
50+
- Updates the password field dynamically when sliders or checkboxes change.
51+
52+
### `private void generatePassword()`
53+
- **Purpose**: Generates a password based on user settings.
54+
- **Dependencies**: Uses `PasswordGenerator.generatePassword` to create a password.
55+
- **Steps**:
56+
1. Retrieves user-selected options (length, character types).
57+
2. Updates `passwordField` with the new password.
58+
3. Calculates and updates the password strength using `PasswordStrengthCalculator`.
59+
60+
### `private void copyPassword()`
61+
- **Purpose**: Copies the generated password to the clipboard.
62+
- **Behavior**:
63+
- Retrieves the password from `passwordField`.
64+
- Copies it to the system clipboard.
65+
- Displays a confirmation dialog.
66+
67+
### `private void savePassword()`
68+
- **Purpose**: Saves the generated password using the `SavePasswordDialog`.
69+
- **Behavior**:
70+
- Prompts the user with a dialog to save the password.
71+
- Validates if a password exists before saving.
72+
73+
### `private JButton createStyledButton(String text)`
74+
- **Purpose**: Creates a styled button for the UI.
75+
- **Parameters**:
76+
- `text`: Label for the button.
77+
- **Returns**: A button with predefined colors, font, and size.
78+
79+
### `private JCheckBox createStyledCheckBox(String text, boolean selected)`
80+
- **Purpose**: Creates a styled checkbox.
81+
- **Parameters**:
82+
- `text`: Label for the checkbox.
83+
- `selected`: Default selection state.
84+
85+
### `private void updateStrengthMeter(JProgressBar meter, int strength)`
86+
- **Purpose**: Updates the strength indicator based on the password's strength score.
87+
- **Behavior**:
88+
- Sets the value, string description, and color of the progress bar.
89+
- **Strength Ranges**:
90+
- `0-2`: Weak (Red color).
91+
- `3-4`: Medium (Yellow color).
92+
- `5`: Strong (Green color).
93+
94+
## Event Listeners
95+
- **Slider**: Updates the password length dynamically.
96+
- **Checkboxes**: Triggers password regeneration when toggled.
97+
- **Buttons**:
98+
- **Generate**: Generates a new password.
99+
- **Copy**: Copies the password to the clipboard.
100+
- **Save**: Saves the password via `SavePasswordDialog`.
101+
102+
## UI Components Layout
103+
1. **Password Display Panel**:
104+
- Displays generated passwords.
105+
- Includes a "Copy" button.
106+
2. **Password Length Section**:
107+
- Slider for password length with a dynamic value display.
108+
3. **Character Types Section**:
109+
- Four checkboxes: Uppercase, Lowercase, Numbers, Symbols.
110+
4. **Password Strength Section**:
111+
- Progress bar to indicate strength visually and textually.
112+
5. **Buttons**:
113+
- "Generate Password" and "Save Password".
114+
115+
## Color Customization
116+
- **Success (Green)**: For strong passwords.
117+
- **Warning (Yellow)**: For medium passwords.
118+
- **Error (Red)**: For weak passwords.
119+
- **Default Text Color (Gray)**: Used for labels and checkboxes.
120+
121+
## Notes
122+
- `PasswordGenerator` and `PasswordStrengthCalculator` are required utilities for this class.
123+
- This class focuses solely on UI and event-driven logic; generation and strength calculation are handled externally.
124+
125+
## Example Usage
126+
```java
127+
PasswordManager passwordManager = new PasswordManager();
128+
GeneratorPanel generatorPanel = new GeneratorPanel(passwordManager);
129+
```

docs/documentation/LoginDialogDoc.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# File: LoginDialog.java
2+
3+
## Overview
4+
`LoginDialog` is a Java class extending `JDialog`. It provides a static method to create and display a login dialog for user authentication in the PasswordSentinel application. The dialog includes username and password fields, along with login functionality.
5+
6+
## Dependencies
7+
- `javax.swing.*`: For UI components (JDialog, JTextField, JPasswordField, JButton, etc.).
8+
- `javax.swing.border.EmptyBorder`: For component padding.
9+
- `java.awt.*`: For layout management and styling.
10+
- `java.awt.event.ActionEvent`, `ActionListener`: For button click events.
11+
12+
## Constants
13+
14+
| Modifier | Type | Name | Value |
15+
|-----------------|---------|--------------------| ------------------------ |
16+
| `private static`| `Color` | `BACKGROUND_COLOR` | `new Color(255, 255, 255)`|
17+
| `private static`| `Color` | `PRIMARY_COLOR` | `new Color(59, 130, 246)`|
18+
| `private static`| `Color` | `TEXT_COLOR` | `new Color(31, 41, 55)` |
19+
| `private static`| `Color` | `BORDER_COLOR` | `new Color(209, 213, 219)`|
20+
21+
## Methods
22+
23+
### `public static void showLoginDialog()`
24+
- **Purpose**: Creates and displays the login dialog.
25+
- **Description**:
26+
- Sets up the dialog properties (size, layout, position).
27+
- Creates and adds UI components (title, username field, password field, login button).
28+
- Implements login validation logic.
29+
30+
### `private static JTextField createStyledTextField(String placeholder)`
31+
- **Purpose**: Creates a styled text field with placeholder functionality.
32+
- **Parameters**:
33+
- `placeholder`: The placeholder text to display.
34+
- **Returns**: A styled `JTextField` with focus listeners for placeholder behavior.
35+
36+
### `private static JPasswordField createStyledPasswordField(String placeholder)`
37+
- **Purpose**: Creates a styled password field with placeholder functionality.
38+
- **Parameters**:
39+
- `placeholder`: The placeholder text to display.
40+
- **Returns**: A styled `JPasswordField` with focus listeners for placeholder and masking behavior.
41+
42+
### `private static JButton createStyledButton(String text)`
43+
- **Purpose**: Creates a styled button for the UI.
44+
- **Parameters**:
45+
- `text`: Label for the button.
46+
- **Returns**: A button with predefined colors, font, and size.
47+
48+
### `private static boolean validateLogin(String username, String password)`
49+
- **Purpose**: Validates the entered credentials.
50+
- **Parameters**:
51+
- `username`: The entered username.
52+
- `password`: The entered password.
53+
- **Returns**: `true` if credentials are valid, `false` otherwise.
54+
- **Note**: Currently set to accept "admin" as both username and password.
55+
56+
## UI Components Layout
57+
1. **Title Label**: "Password Sentinel"
58+
2. **Username Field**: Text field with "Username" placeholder
59+
3. **Password Field**: Password field with "Password" placeholder
60+
4. **Login Button**: "Sign In" button
61+
5. **Error Label**: Displays error messages for invalid login attempts
62+
63+
## Event Listeners
64+
- **Login Button**: Triggers login validation on click.
65+
- **Text Fields**: Focus listeners for placeholder behavior.
66+
67+
## Login Process
68+
1. User enters username and password.
69+
2. User clicks "Sign In" button.
70+
3. `validateLogin()` is called to check credentials.
71+
4. If valid, the dialog closes and `PasswordSentinel` main window opens.
72+
5. If invalid, an error message is displayed.
73+
74+
## Styling Details
75+
- **Dialog Size**: 350x400 pixels
76+
- **Background Color**: White
77+
- **Primary Color** (for title and button): Blue (59, 130, 246)
78+
- **Text Color**: Dark gray (31, 41, 55)
79+
- **Border Color**: Light gray (209, 213, 219)
80+
- **Font**: Arial, various sizes and styles
81+
82+
## Notes
83+
- The dialog is non-resizable and centered on the screen.
84+
- Placeholder text is implemented for both username and password fields.
85+
- The current login validation is a placeholder and should be replaced with actual authentication logic.
86+
87+
## Example Usage
88+
```java
89+
SwingUtilities.invokeLater(LoginDialog::showLoginDialog);
90+
```

0 commit comments

Comments
 (0)