Skip to content
Merged
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
57 changes: 57 additions & 0 deletions Password Manager/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Password Manager

## Usage
Run the pwd_mgmr.py file and you will be prompted for the rest of the required inputs

### Getting Started:
1. Select Option (1) Create a new key that will be used to encrypt your password file.
2. Select Option (3) Create a new password file that will be used to hold your encrypted passwords.
3. Select Option (5) Add a new password to the password file. \n

### Retrieving or Adding Passords:
1. Select Option (2) Load the existing key so it can be used to encrypt new passwords or retrieve passwords from the password file.
2. Select Option (4) Load the existing password file so it can be used to add or retrieve passwords.
3. Select Option (5) Add a new password to the password file.
4. Select Option (6) Retrieve a password for a site.

## Example

What would you like to do?
(1) Create a new key
(2) Load an existing key
(3) Create new password file
(4) Load existing password file
(5) Add a new password
(6) Get a password for a site
(7) Get the list of sites
(m) Menu
(h) Help
(q) Quit
Enter your choice: h
Getting Started:
1. Select Option (1) Create a new key that will be used to encrypt your password file.
2. Select Option (3) Create a new password file that will be used to hold your encrypted passwords.
3. Select Option (5) Add a new password to the password file.

Retrieving or Adding Passords:
1. Select Option (2) Load the existing key so it can be used to encrypt new passwords or retrieve passwords from the password file.
2. Select Option (4) Load the existing password file so it can be used to add or retrieve passwords.
3a. Select Option (5) Add a new password to the password file.
3b. Select Option (6) Retrieve a password for a site.
Enter your choice: 1
Invalid Choice!
Enter your choice: 1
Enter the path: C:\pwds\mykey.key
Enter your choice: 3
Enter the path: C:\pwds\pwds.pass
Enter your choice: 5
Enter the site: facebook
Enter the password: password123
Enter your choice: 6
What site do you want: facebook
password123
Enter your choice: 7
List of Sites:
facebook
Enter your choice: q
Bye!
121 changes: 121 additions & 0 deletions Password Manager/pwd_mgmr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
from cryptography.fernet import Fernet
# Symmetric Key Encyrption Class

# Password Manager Class that will create & load passwords from an encrypted file
class PasswordManager:
def __init__(self):
self.key = None
self.pwd_file = None
self.pwd_dict = {}

def create_key(self, path):
self.key = Fernet.generate_key()
with open(path, 'wb') as f:
f.write(self.key)

def load_key(self, path):
with open(path, 'rb') as f:
self.key = f.read()

# init_values is a dictionary
def create_pwd_file(self, path, init_values=None):
self.pwd_file = path
if init_values is not None:
for key, values in init_values.items():
self.add_password(self, key, values)

def load_pwd_file(self, path):
self.pwd_file = path
with open(path, 'r') as f:
for line in f:
site, encrypted = line.split(":")
# Loads the site and the associated encrypted password. Password must be encoded before decyprtion and decoded before returning text
self.pwd_dict[site] = Fernet(self.key).decrypt(encrypted.encode()).decode()

def add_password(self, site, password):
self.pwd_dict[site] = password
if self.pwd_file is not None:
with open(self.pwd_file, 'a') as f:
encrypted = Fernet(self.key).encrypt(password.encode())
s = ":"
written = site + s + encrypted.decode() + "\n"
f.write(written)

def get_password(self, site):
return self.pwd_dict[site]

def get_sites(self):
print("List of Sites:")
for a in self.pwd_dict.keys():
print(a)

def main():
pm = PasswordManager()
print("""What would you like to do?
(1) Create a new key
(2) Load an existing key
(3) Create new password file
(4) Load existing password file
(5) Add a new password
(6) Get a password for a site
(7) Get the list of sites
(m) Menu
(h) Help
(q) Quit""")
done = False

while not done:

choice = input("Enter your choice: ")
choice = choice.lower()
match choice:
case "1":
path = input("Enter the path: ")
pm.create_key(path)
case "2":
path = input("Enter the path: ")
pm.load_key(path)
case "3":
path = input("Enter the path: ")
pm.create_pwd_file(path, init_values=None)
case "4":
path = input ("Enter the path: ")
pm.load_pwd_file(path)
case "5":
site = input("Enter the site: ")
password = input("Enter the password: ")
pm.add_password(site, password)
case "6":
site = input("What site do you want: ")
print(pm.get_password(site))
case "7":
pm.get_sites()
case "m":
print("""What would you like to do?
(1) Create a new key
(2) Load an existing key
(3) Create new password file
(4) Load existing password file
(5) Add a new password
(6) Get a password for a site
(m) Menu
(h) Help
(q) Quit""")
case "h":
print("""Getting Started:
1. Select Option (1) Create a new key that will be used to encrypt your password file.
2. Select Option (3) Create a new password file that will be used to hold your encrypted passwords.
3. Select Option (5) Add a new password to the password file. \n
Retrieving or Adding Passords:
1. Select Option (2) Load the existing key so it can be used to encrypt new passwords or retrieve passwords from the password file.
2. Select Option (4) Load the existing password file so it can be used to add or retrieve passwords.
3a. Select Option (5) Add a new password to the password file.
3b. Select Option (6) Retrieve a password for a site.""")
case "q":
done = True
print("Bye!")
case _:
print("Invalid Choice!")

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Incase there is something that needs to be followed while executing the python s
| No Screensaver | [No Screensaver](https://github.com/DhanushNehru/Python-Scripts/tree/master/Noscreensaver) | Prevents screensaver from turning on. |
| OTP Verification | [OTP Verification](https://github.com/DhanushNehru/Python-Scripts/tree/master/OTP%20%20Verify) | An OTP Verification Checker OTPVerification.py |
| Password Generator | [Password Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Password%20Generator) | Generates a random password |
| Password Manager | [Password Manager](https://github.com/nem5345/Python-Scripts/tree/master/Password%20Manager) | Generate and interact with a password manager |
| PDF to Audio | [PDF to Audio](https://github.com/DhanushNehru/Python-Scripts/tree/master/PDF%20to%20Audio) | Converts PDF to audio. |
| Planet Simulation | [Planet Simulation](https://github.com/DhanushNehru/Python-Scripts/tree/master/planetSimulation) | A simulation of several planets rotating around the sun. |
| Popup Window | [Popup Window](https://github.com/DhanushNehru/Python-Scripts/tree/master/Display%20Popup%20Window) | Displaying a popup window DisplayPopupWindow.py |
Expand Down