-
Notifications
You must be signed in to change notification settings - Fork 0
/
passwordmanager.py
31 lines (25 loc) · 1.14 KB
/
passwordmanager.py
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
import secrets
import string
# Generate a random password
def generate_password(length=16):
characters = string.ascii_letters + string.digits + string.punctuation
password = "".join(secrets.choice(characters) for i in range(length))
return password
# Store a password in a secure way
def store_password(service, username, password):
# Use a secure hashing function to store the password
hashed_password = hash_function(password)
# Store the hashed password in a database or file
with open("password_database.txt", "a") as f:
f.write(f"{service},{username},{hashed_password}\n")
# Retrieve a password
def get_password(service, username):
# Look up the hashed password in the database or file
with open("password_database.txt") as f:
for line in f:
service_, username_, hashed_password_ = line.strip().split(",")
if service == service_ and username == username_:
# Use a secure hashing function to compare the stored password with the provided password
if hash_function(password) == hashed_password_:
return password
return None