-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject_four.py
More file actions
48 lines (32 loc) · 887 Bytes
/
Copy pathProject_four.py
File metadata and controls
48 lines (32 loc) · 887 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import bcrypt
import os
FILE_NAME = "password.txt"
def register():
password = input("Create a password: ")
hashed_password = bcrypt.hashpw(
password.encode("utf-8"),
bcrypt.gensalt()
)
with open(FILE_NAME, "wb") as f:
f.write(hashed_password)
print("Registration successful!")
def login():
password = input("Enter password: ")
with open(FILE_NAME, "rb") as f:
stored_hash = f.read()
if bcrypt.checkpw(password.encode("utf-8"), stored_hash):
print("Login successful!")
else:
print("Login failed!")
print("1. Register")
print("2. Login")
choice = input("Choose an option: ")
if choice == "1":
register()
elif choice == "2":
if not os.path.exists(FILE_NAME):
print("No user registered yet. Please register first.")
else:
login()
else:
print("Invalid choice")