Skip to content

Commit 753a879

Browse files
Create PasswordManager.py
1 parent 2f8288f commit 753a879

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

PasswordManager.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import secrets
2+
import string
3+
4+
# Generate a random password
5+
def generate_password(length=16):
6+
characters = string.ascii_letters + string.digits + string.punctuation
7+
password = "".join(secrets.choice(characters) for i in range(length))
8+
return password
9+
10+
# Store a password in a secure way
11+
def store_password(service, username, password):
12+
# Use a secure hashing function to store the password
13+
hashed_password = hash_function(password)
14+
15+
# Store the hashed password in a database or file
16+
with open("password_database.txt", "a") as f:
17+
f.write(f"{service},{username},{hashed_password}\n")
18+
19+
# Retrieve a password
20+
def get_password(service, username):
21+
# Look up the hashed password in the database or file
22+
with open("password_database.txt") as f:
23+
for line in f:
24+
service_, username_, hashed_password_ = line.strip().split(",")
25+
if service == service_ and username == username_:
26+
# Use a secure hashing function to compare the stored password with the provided password
27+
if hash_function(password) == hashed_password_:
28+
return password
29+
return None

0 commit comments

Comments
 (0)