-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathact-01-5.py
47 lines (43 loc) · 1.27 KB
/
act-01-5.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Now let's make that REPL!!!
MAX_FAILED = 3
# our users database is similar to a constant.
# although we might add users, it's something
# global (at the top-level, on the left) and it's
# good to differentiate it. we use it mostly like a constant
USERS = {
"admin": {
"name": "Administrator",
"password": "password",
"failed": 0,
},
"member": {
"name": "ProgSoc Guest Account",
"password": "pogsoc2024",
"failed": 0,
},
"oli": {
"name": "Oli",
"password": "this-is-actually-my-1-real-password-or-is-it?",
"failed": 0,
}
}
# log-in loop
while True:
print("="*40)
print("Welcome to the Python Repl for Offline Grokking of Snake Oriented Code (PROGSOC)")
print("="*40)
username = input("Username: ")
password = input("Password: ")
if username in USERS:
user = USERS[username]
if password == user["password"]:
print("Access Granted.")
print(f"Welcome {user["name"]} to PROGSOC!")
else:
user["failed"] += 1
print(f"Access Denied. {MAX_FAILED - user["failed"]} attempt{"s" if user["failed"] != 1 else ""} remaining.")
if user["failed"] >= MAX_FAILED:
print("ALARM RAISED. SELF-DESTRUCT SEQUENCE ENGAGING...")
break
else:
print("Sorry, we don't know that user. Try again.")