From 5d490a3f18fad2b3576c39c1b12eedb9aaebb0e6 Mon Sep 17 00:00:00 2001 From: Entity069 Date: Tue, 17 Dec 2024 19:01:09 +0530 Subject: [PATCH 1/2] Added a GUI in QT --- README.md | 37 +---------- gui_manager.py | 166 +++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 58 +++-------------- 3 files changed, 176 insertions(+), 85 deletions(-) create mode 100644 gui_manager.py diff --git a/README.md b/README.md index 00acea3..b0944ce 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ A **CLI-based password manager** built in Python for secure password storage and / ├── main.py # Entry point for executing the program ├── manager.py # Core logic and functionality +├── gui_manager.py # GUI component ``` --- @@ -64,7 +65,7 @@ Visit the **python** channel and ping `2Y` for assistance. 4. **Install required dependencies**: ```bash - pip install cryptography + pip install cryptography PyQt5 ``` 5. **Run the Application**: @@ -97,40 +98,8 @@ Visit the **python** channel and ping `2Y` for assistance. ``` 2. **Menu Options**: - - `1`: Create a new encryption key. - - `2`: Load an existing encryption key. - - `3`: Create a new password file. - - `4`: Load an existing password file. - - `5`: Add a new password to the file. - - `6`: Retrieve a password from the file. - - `q`: Quit the application. ---- - -## Example Usage - -### Create a New Key - -```bash -Enter choice: 1 -Enter key file path: keyfile.key -``` - -### Add a New Password - -```bash -Enter choice: 5 -Enter site: github -Enter password: securepassword123 -``` - -### Retrieve a Password - -```bash -Enter choice: 6 -Enter site: github -Password for github is securepassword123 -``` +Follow the GUI. --- diff --git a/gui_manager.py b/gui_manager.py new file mode 100644 index 0000000..964be08 --- /dev/null +++ b/gui_manager.py @@ -0,0 +1,166 @@ +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLineEdit, QLabel, QFileDialog, QMessageBox +from manager import PasswordManager + + +class PasswordManagerGUI(QWidget): + def __init__(self): + super().__init__() + self.pm = PasswordManager() + self.key_loaded = False + self.file_loaded = False + + self.init_ui() + + def init_ui(self): + self.setWindowTitle("Password Manager") + self.setGeometry(100, 100, 500, 500) + self.setStyleSheet("font-family: Arial; font-size: 12pt;") + + self.layout = QVBoxLayout(self) + + self.step1_layout = QVBoxLayout() + self.step1_title = QLabel("Step 1: Key Management") + self.step1_layout.addWidget(self.step1_title) + + self.create_key_button = QPushButton("Create New Key") + self.create_key_button.clicked.connect(self.create_key) + self.step1_layout.addWidget(self.create_key_button) + + self.load_key_button = QPushButton("Load Existing Key") + self.load_key_button.clicked.connect(self.load_key) + self.step1_layout.addWidget(self.load_key_button) + + self.key_file_label = QLabel("No key file loaded.") + self.step1_layout.addWidget(self.key_file_label) + + self.step2_layout = QVBoxLayout() + self.step2_title = QLabel("Step 2: Password File Management") + self.step2_layout.addWidget(self.step2_title) + + self.create_file_button = QPushButton("Create New Password File") + self.create_file_button.clicked.connect(self.create_password_file) + self.step2_layout.addWidget(self.create_file_button) + + self.load_file_button = QPushButton("Load Existing Password File") + self.load_file_button.clicked.connect(self.load_password_file) + self.step2_layout.addWidget(self.load_file_button) + + self.password_file_label = QLabel("No password file loaded.") + self.step2_layout.addWidget(self.password_file_label) + + + self.step3_layout = QVBoxLayout() + self.step3_title = QLabel("Step 3: Manage Passwords") + self.step3_layout.addWidget(self.step3_title) + + self.site_layout = QHBoxLayout() + self.site_label = QLabel("Site:") + self.site_layout.addWidget(self.site_label) + + self.site_entry = QLineEdit(self) + self.site_layout.addWidget(self.site_entry) + self.step3_layout.addLayout(self.site_layout) + + self.password_layout = QHBoxLayout() + self.password_label = QLabel("Password:") + self.password_layout.addWidget(self.password_label) + + self.password_entry = QLineEdit(self) + self.password_entry.setEchoMode(QLineEdit.Password) + self.password_layout.addWidget(self.password_entry) + self.step3_layout.addLayout(self.password_layout) + + self.add_button = QPushButton("Add Password") + self.add_button.clicked.connect(self.add_password) + self.step3_layout.addWidget(self.add_button) + + self.get_button = QPushButton("Get Password") + self.get_button.clicked.connect(self.get_password) + self.step3_layout.addWidget(self.get_button) + + self.layout.addLayout(self.step1_layout) + self.layout.addLayout(self.step2_layout) + self.layout.addLayout(self.step3_layout) + + self.step2_layout.setEnabled(False) + self.step3_layout.setEnabled(False) + + def create_key(self): + path, _ = QFileDialog.getSaveFileName(self, "Create Key File", "", "Key Files (*.key);;All Files (*)") + if path: + if not path.endswith(".key"): + path += ".key" + self.pm.create_key(path) + self.key_loaded = True + self.key_file_label.setText(f"Key file loaded: {path}") + QMessageBox.information(self, "Success", f"New key created at {path}") + self.step2_layout.setEnabled(True) + + + def load_key(self): + path, _ = QFileDialog.getOpenFileName(self, "Open Key File", "", "Key Files (*.key);;All Files (*)") + if path: + self.pm.load_key(path) + self.key_loaded = True + self.key_file_label.setText(f"Key file loaded: {path}") + QMessageBox.information(self, "Success", f"Key loaded successfully from {path}") + self.step2_layout.setEnabled(True) + else: + self.key_loaded = False + + def create_password_file(self): + if not self.key_loaded: + QMessageBox.warning(self, "Error", "Please load or create a key file first!") + return + + path, _ = QFileDialog.getSaveFileName(self, "Create Password File", "", "Text Files (*.txt);;All Files (*)") + if path: + if not path.endswith(".txt"): + path += ".txt" + self.pm.create_password_file(path) + self.file_loaded = True + self.password_file_label.setText(f"Password file loaded: {path}") + QMessageBox.information(self, "Success", f"New password file created at {path}") + self.step3_layout.setEnabled(True) + + + def load_password_file(self): + if not self.key_loaded: + QMessageBox.warning(self, "Error", "Please load or create a key file first!") + return + + path, _ = QFileDialog.getOpenFileName(self, "Open Password File", "", "Text Files (*.txt);;All Files (*)") + if path: + self.pm.load_password_file(path) + self.file_loaded = True + self.password_file_label.setText(f"Password file loaded: {path}") + QMessageBox.information(self, "Success", f"Password file loaded successfully from {path}") + self.step3_layout.setEnabled(True) + else: + self.file_loaded = False + + def add_password(self): + if not self.key_loaded or not self.file_loaded: + QMessageBox.warning(self, "Error", "Please load or create both a key and a password file first!") + return + + site = self.site_entry.text().strip() + password = self.password_entry.text().strip() + if site and password: + self.pm.add_password(site, password) + QMessageBox.information(self, "Success", f"Password for {site} added successfully!") + else: + QMessageBox.warning(self, "Error", "Both site and password fields must be filled!") + + def get_password(self): + if not self.key_loaded or not self.file_loaded: + QMessageBox.warning(self, "Error", "Please load or create both a key and a password file first!") + return + + site = self.site_entry.text().strip() + if site: + password = self.pm.get_password(site) + QMessageBox.information(self, "Password", f"Password for {site}: {password}") + else: + QMessageBox.warning(self, "Error", "Please enter a site!") + diff --git a/main.py b/main.py index 57ab52b..c34d953 100644 --- a/main.py +++ b/main.py @@ -1,53 +1,9 @@ -from manager import PasswordManager - - -def main(): - password = { - "gmail": "password1", - "facebook": "password2", - "twitter": "password3" - } - - pm = PasswordManager() - - print("""What would you like to do? - 1. Create a new key - 2. Load an existing key - 3. Create a new password file - 4. Load an existing password file - 5. Add a password - 6. Get a password - q. Quit - """) - - done = False - while not done: - choice = input("Enter choice: ").strip().lower() - if choice == '1': - path = input("Enter key file path: ").strip() - pm.create_key(path) - elif choice == '2': - path = input("Enter key file path: ").strip() - pm.load_key(path) - elif choice == '3': - path = input("Enter password file path: ").strip() - pm.create_password_file(path, password) - elif choice == '4': - path = input("Enter password file path: ").strip() - pm.load_password_file(path) - elif choice == '5': - site = input("Enter site: ").strip() - password = input("Enter password: ").strip() - pm.add_password(site, password) - elif choice == '6': - site = input("Enter site: ").strip() - print(f"Password for {site}: {pm.get_password(site)}") - elif choice == 'q': - done = True - print("Goodbye!") - else: - print("Invalid choice. Please try again.") - +from gui_manager import PasswordManagerGUI +import sys +from PyQt5.QtWidgets import QApplication if __name__ == '__main__': - main() + app = QApplication(sys.argv) + window = PasswordManagerGUI() + window.show() + sys.exit(app.exec_()) \ No newline at end of file From bce1ee67635fd07cd1b3f6f191329205373b21c8 Mon Sep 17 00:00:00 2001 From: Entity069 Date: Wed, 18 Dec 2024 15:25:39 +0530 Subject: [PATCH 2/2] Updated README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b0944ce..d6529c0 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,8 @@ Visit the **python** channel and ping `2Y` for assistance. - **Encrypt and Store Passwords**: Securely save your credentials. - **Key Management**: Generate and load encryption keys. -- **File-Based Storage**: Organize passwords in a file. +- **File-Based Storage**: Organize passwords in a file. +- **Simple GUI**: A simple GUI made in QT for interactivity. ---