Skip to content

Commit

Permalink
Revert "Added a database-based multi-user feature (IMGIITRoorkee#101)" (
Browse files Browse the repository at this point in the history
IMGIITRoorkee#120)

This reverts commit 3b03391.
  • Loading branch information
fillingtothemomo authored Jan 3, 2025
1 parent 64ab972 commit f9ab147
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 237 deletions.
54 changes: 36 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ 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
├── user_handler.py # User handling
├── database.py # Database schema
```
### Install required dependencies:
`pip install -r requirements.txt`
Expand Down Expand Up @@ -68,7 +66,7 @@ Visit the **python** channel and ping `2Y` for assistance.

4. **Install required dependencies**:
```bash
pip install cryptography sqlalchemy
pip install cryptography
```

5. **Run the Application**:
Expand All @@ -82,14 +80,14 @@ Visit the **python** channel and ping `2Y` for assistance.

- **Encrypt and Store Passwords**: Securely save your credentials.
- **Key Management**: Generate and load encryption keys.
- **Database-Based Storage**: Organize passwords in a database.
- **File-Based Storage**: Organize passwords in a file.

---

## Requirements

- **Python**: Version 3.x or higher.
- **Library**: `cryptography` and `sqlalchemy`
- **Library**: `cryptography`

---

Expand All @@ -100,24 +98,44 @@ Visit the **python** channel and ping `2Y` for assistance.
python3 main.py
```

2. **Menu Options**:

**Login Menu**
- `1`: Register a user.
- `2`: Login using existing user credentials.
- `q`: Quit the application.

**Application Menu**
- `1`: List all existing keys created by a user.
2. **Menu Options**:
- `1`: Create a new encryption key.
- `2`: Load an existing encryption key.
- `3`: Create a new key.
- `4`: Add a new password to the file.
- `5`: Retrieve a password.
- `6`: List all sites for which password are saved.
- `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
```

---

## Security Note

- **Keep Your Encryption Key Safe**:
Expand Down
47 changes: 0 additions & 47 deletions database.py

This file was deleted.

143 changes: 64 additions & 79 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,80 @@
from database import Database
from user_handler import UserHandler
from manager import PasswordManager
import pyperclip

def main():
db = Database()
session = db.get_session()
user_handler = UserHandler(session)

print("Welcome to the Multi-User Password Manager!")
current_user = None

while not current_user:
print("\n1. Register\n2. Login\nq. Quit")
choice = input("Enter choice: ").strip().lower()

if choice == '1':
username = input("Enter username: ").strip()
password = input("Enter password: ").strip()
try:
user_handler.register_user(username, password)
print("Registration successful!")
except:
print("Username already exists. Try a different one.")

elif choice == '2':
username = input("Enter username: ").strip()
password = input("Enter password: ").strip()
user = user_handler.authenticate_user(username, password)
if user:
print(f"Welcome, {username}!")
current_user = user
else:
print("Invalid credentials. Please try again.")

elif choice == 'q':
print("Goodbye!")
return

else:
print("Invalid choice. Try again.")

pm = PasswordManager(session, current_user)
def validate_key_loaded(pm : PasswordManager):
if not pm.keyloaded:
print("Key not loaded. Please load a key first.")
return False
return True

while True:
print("""
1. List Available Keys
2. Select a Key
3. Add a New Key
4. Add Password (Using Selected Key)
5. Retrieve Password
6. List Sites
q. Quit
""")
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
7. List all sites
q. Quit
""")

done = False
while not done:
choice = input("Enter choice: ").strip().lower()

if choice == '1':
pm.list_keys()

path = input("Enter key file path: ").strip()
pm.create_key(path)
elif choice == '2':
keys = pm.list_keys()
if keys:
key_id = input("Enter the Key ID to select: ").strip()
pm.load_key(key_id)

elif choice == '3':
pm.add_new_key()

elif choice == '4':
if not pm.key:
print("Please select a key first.")
continue
site = input("Enter site name: ").strip()
password_value = input("Enter password: ").strip()
pm.add_password(site, password_value)

elif choice == '5':
site = input("Enter site name to retrieve password: ").strip()
password = pm.get_password(site)
print(f"Password for {site}: {password}")

elif choice == '6':
pm.list_sites()

path = input("Enter key file path: ").strip()
pm.load_key(path)
elif choice == '3' and validate_key_loaded(pm):
path = input("Enter password file path: ").strip()
pm.create_password_file(path, password)
elif choice == '4' and validate_key_loaded(pm):
path = input("Enter password file path: ").strip()
pm.load_password_file(path)
elif choice == '5' and validate_key_loaded(pm):
site = input("Enter site: ").strip()
password = input("Enter password: ").strip()
if pm.validate_strength(password):
print("added successfully")
else:
print("WARNING: This password is weak, It is recommended to set a stronger password")
print("- Password should be more than 8 characters long")
print("- Password should have alphanumeric characters, capital letters and special characters")
pm.add_password(site, password)

elif choice == '6' and validate_key_loaded(pm):

site = input("Enter site: ").strip()
res = pm.get_password(site)
print(f"Password for {site}: {res}")
if(res != "Password not found."):
pyperclip.copy(pm.get_password(site))
print("Password copied to clipboard.")

elif choice == '7':
print("Saved Sites:")
for site in pm.password_dict:
print(site)
elif choice == 'q':
done = True
print("Goodbye!")
break

else:
print("Invalid choice. Try again.")
print("Invalid choice. Please try again.")


if __name__ == "__main__":
if __name__ == '__main__':
main()
Loading

0 comments on commit f9ab147

Please sign in to comment.