-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswordManager.py
More file actions
101 lines (77 loc) · 3.33 KB
/
passwordManager.py
File metadata and controls
101 lines (77 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from cryptography.fernet import Fernet
# Mini Password Manager (Python)
This is a simple password manager built in Python that allows you to **add**, **view**, and **update** passwords securely using **Fernet encryption** from the `cryptography` library.
## Features
- Store usernames and encrypted passwords in a text file.
- Encrypts passwords so that even if the file is accessed, passwords remain secure.
- Supports adding new credentials, viewing existing ones, and updating passwords.
- Easy to use in the terminal.
## How it works
1. A symmetric key (`key.key`) is used for encryption/decryption.
2. User passwords are encrypted before storing in `passwords.txt`.
3. When viewing or updating, passwords are decrypted on the fly.
4. Each username:password pair is stored in the format:
# Mini Password Manager (Python)
This is a simple password manager built in Python that allows you to **add**, **view**, and **update** passwords securely using **Fernet encryption** from the `cryptography` library.
## Features
- Store usernames and encrypted passwords in a text file.
- Encrypts passwords so that even if the file is accessed, passwords remain secure.
- Supports adding new credentials, viewing existing ones, and updating passwords.
- Easy to use in the terminal.
## How it works
1. A symmetric key (`key.key`) is used for encryption/decryption.
2. User passwords are encrypted before storing in `passwords.txt`.
3. When viewing or updating, passwords are decrypted on the fly.
4. Each username:password pair is stored in the format:
"""def write_key():
key=Fernet.generate_key()
with open("key.key","wb") as key_file: #wb-write bytes
key_file.write(key)"""
def load_key():
file=open("key.key","rb")
key=file.read()
file.close()
return key
key=load_key()
fer=Fernet(key)
def view_password():
with open("passwords.txt",'r') as f:
for line in f.readlines():
data=line.rstrip()
user,passw=data.split(" : ")
print("Username: "+user+" , Password: "+fer.decrypt(passw.encode()).decode())
def add_password():
username=input("enter username: ")
password=input("enter password: ")
with open("passwords.txt",'a') as f: #mode 'a'-appends 'w'-write 'r'-read
f.write(username+" : "+ fer.encrypt(password.encode()).decode()+"\n")
def update_password():
req_username=input("enter the username to be updated ")
with open("passwords.txt","r") as f:
lines=f.readlines()
updated=False
new_lines=[]
for line in lines:
user,passw=line.rstrip().split(" : ")
if req_username==user:
new_password=input("enter new password: ")
new_lines.append(f"{user} : {fer.encrypt(new_password.encode()).decode()}\n")
updated=True
else:
new_lines.append(line)
with open("passwords.txt","w") as f:
f.writelines(new_lines)
if(updated):
print("password updated successfully")
else:
print("username not found")
while True:
mode=input("Would you like to add a new password , view on existing one , or update an old one? (enter add/view/update/quit) ").lower();
if(mode=="quit"):
break
elif(mode=="view"):
view_password()
elif(mode=="add"):
add_password()
elif(mode=="update"):
update_password()