From 59a0c81ded892ec78be1d8c72892fdb45d1298c0 Mon Sep 17 00:00:00 2001 From: nem5345 <60441632+nem5345@users.noreply.github.com> Date: Sun, 7 May 2023 17:11:38 -0400 Subject: [PATCH 1/2] Added & Tested Password Manager --- Password Manager/README.MD | 57 +++++++++++++++++ Password Manager/pwd_mgmr.py | 121 +++++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 Password Manager/README.MD create mode 100644 Password Manager/pwd_mgmr.py diff --git a/Password Manager/README.MD b/Password Manager/README.MD new file mode 100644 index 00000000..3370be0d --- /dev/null +++ b/Password Manager/README.MD @@ -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! diff --git a/Password Manager/pwd_mgmr.py b/Password Manager/pwd_mgmr.py new file mode 100644 index 00000000..c859dbbb --- /dev/null +++ b/Password Manager/pwd_mgmr.py @@ -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() \ No newline at end of file From 31e01d58f3e1e03ff497418b212bce373a715bcf Mon Sep 17 00:00:00 2001 From: nem5345 <60441632+nem5345@users.noreply.github.com> Date: Sun, 7 May 2023 17:14:25 -0400 Subject: [PATCH 2/2] Updated Large README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 000e79b8..48d809ac 100644 --- a/README.md +++ b/README.md @@ -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 |