Skip to content

Commit 5081ca7

Browse files
committed
commit to 'main'
1 parent 530dfb3 commit 5081ca7

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

Python-games/Key.key

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5LtbAO9oGGRrILLX7HIxIQmwFdoPfNMNLO5KrdQcYz8=

Python-games/choose_your_own_adventure.py

Whitespace-only changes.

Python-games/password_manager.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Importing Library for encrypting:
2+
from cryptography.fernet import Fernet
3+
4+
# Creating a key file to encrypt the password file
5+
# One-time process***
6+
# def create_key():
7+
# key = Fernet.generate_key()
8+
# with open('Key.key', 'wb') as key_file:
9+
# key_file.write(key)
10+
11+
# create_key()
12+
13+
def load_key():
14+
file = open('Python-games/Key.key', 'rb')
15+
key = file.read()
16+
file.close()
17+
return key
18+
19+
20+
master_pwd = input("Enter the Master Password: ")
21+
mas_key = load_key() + master_pwd.encode()
22+
fer = Fernet(mas_key)
23+
24+
# Functional programming Approach:
25+
def view():
26+
# Reading the txt file in read mode:
27+
with open('Python-games/passwords.txt', 'r') as pwd_file:
28+
for line in pwd_file.readlines():
29+
view_uname, view_pwd = line.rstrip('\n').split(': ')
30+
print(f"Username: {view_uname}; Password: {fer.decrypt(view_pwd.encode()).decode()}")
31+
32+
def add():
33+
username = input("Username: ")
34+
password = input("Password: ")
35+
36+
# Writing to the file in Append mode:
37+
with open('Python-games/passwords.txt', 'a') as pwd_file:
38+
pwd_file.write(f"{username}: {fer.encrypt(password.encode()).decode()}\n")
39+
40+
while True:
41+
mode = input("\nDo you want to add a new password or view the exisiting password?\n (Choose: [View/Add] [Q/q] to quit) \n")
42+
if (str(mode).lower() == 'q'):
43+
break
44+
elif (str(mode).lower() == 'view'):
45+
view()
46+
47+
elif (str(mode).lower() == 'add'):
48+
add()
49+
50+
else:
51+
print("Invalid Mode.")
52+
continue

Python-games/passwords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
visc: gAAAAABi2pi2lQ_sfsPTN5gtehTx8DqepgRrDK_ehSjfbZ4my4SpwXrLxTuyKDvG8rU-9jF8tgabPNcLJfptBfdL1JhnWr48lw==

0 commit comments

Comments
 (0)