Repository navigation
Expand file tree
/
Copy pathauth.py
More file actions
64 lines (51 loc) · 1.55 KB
/
Copy pathauth.py
File metadata and controls
64 lines (51 loc) · 1.55 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import database
import crypt
import config
logged_in = False
current_username = config.DEFAULT_USER
current_password = ""
## Check if the current user is logged in
def get_logged_in():
return logged_in
## Set the current user's authentication status
def set_logged_in(status):
global logged_in
logged_in = status
## Get the current user's username
def get_current_user():
return current_username
## Set the current user's username
def set_current_user(username):
global current_username
current_username = username
## Get the current user's password
def get_current_pass():
return current_password
## Set the current user's password
def set_current_pass(password):
global current_password
current_password = password
## Check through the database to check if the user exists
def user_exists(username, password):
db = database.read()
encrypted_password = crypt.encrypt(password, password)
print("encp: {}".format(encrypted_password))
for row in db:
if row[0] == username and row[1] == encrypted_password:
global logged_in
logged_in = True
return logged_in
## Attempt to log the user in assuming the credentials are valid
def login(username, password):
if not user_exists(username, password):
return False
set_logged_in(True)
set_current_user(username)
set_current_pass(password)
return True
## Log the user out and wipe local login credentials
def logout():
set_logged_in(False)
set_current_user("unknown")
set_current_pass("")
return True