-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
32 lines (25 loc) · 879 Bytes
/
auth.py
File metadata and controls
32 lines (25 loc) · 879 Bytes
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
import os
import hashlib
import getpass
MASTER_PASSWORD_FILE = "master.key"
def hash_password(password):
return hashlib.sha256(password.encode()).hexdigest()
def set_master_password():
password = getpass.getpass("Set your master password: ")
hashed = hash_password(password)
with open(MASTER_PASSWORD_FILE, "w") as file:
file.write(hashed)
print("✅ Master password set successfully!")
def verify_master_password():
if not os.path.exists(MASTER_PASSWORD_FILE):
set_master_password()
password = getpass.getpass("Enter master password: ")
hashed = hash_password(password)
with open(MASTER_PASSWORD_FILE, "r") as file:
stored_hash = file.read()
if hashed == stored_hash:
print("✅ Access granted!")
return True
else:
print("❌ Access denied! Wrong password.")
return False