/
auth.py
35 lines (29 loc) · 1.03 KB
/
auth.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
from agent import Agent, Supervisor
from constants import AGENTS_FILE_PATH
from store import load_data
def check_agent_username(username):
agents_data = load_data(AGENTS_FILE_PATH)
_ = [Agent(**d) for d in agents_data]
agent = Supervisor.search_username(username)
return agent
def check_agent_password(agent, password):
if agent.check_password(password):
return True
return False
def agent_auth():
agent = None
password_is_correct = False
while agent is None:
username = input('Please enter your username:')
agent = check_agent_username(username)
if agent is None:
print('This username not found, try again...')
while password_is_correct is False:
password = input('Please enter your password:')
password_is_correct = check_agent_password(agent, password)
if password_is_correct:
print('Welcome Back!!!')
password_is_correct = True
else:
print('Password is wrong, try again...')
return agent