forked from BCCN-Prog/2019_day1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
executable file
·45 lines (36 loc) · 1.02 KB
/
Copy pathauth.py
File metadata and controls
executable file
·45 lines (36 loc) · 1.02 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
import pickle
def get_credentials():
username = input("Enter username:")
password = input("Enter password:")
return (username, password)
def authenticate(username, password, pwdb):
status = False
if username in pwdb:
if password == pwdb[username]:
status = True
else:
print('Wrong password!')
else:
add_user(username, password, pwdb)
return status
def add_user(username, password, pwdb):
pwdb[username] = password
write_pwdb(pwdb)
def read_pwdb():
try:
with open("pwdb.pkl", "rb") as fh:
pwdb = pickle.load(fh)
except FileNotFoundError:
pwdb = {}
return pwdb
def write_pwdb(pwdb):
with open("pwdb.pkl", "wb") as fh:
pickle.dump(pwdb, fh)
if __name__ == "__main__":
username, password = get_credentials()
pwdb = read_pwdb()
status = authenticate(username, password, pwdb)
if status:
print('Authentication succeeded:', pwdb)
else:
print('Authentication failed')