Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a GUI in QT (new) #102

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 5 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

---
Expand Down Expand Up @@ -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**:
Expand All @@ -78,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.

---

Expand All @@ -97,40 +99,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.

---

Expand Down
166 changes: 166 additions & 0 deletions gui_manager.py
Original file line number Diff line number Diff line change
@@ -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!")

58 changes: 7 additions & 51 deletions main.py
Original file line number Diff line number Diff line change
@@ -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_())