-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauth.py
51 lines (43 loc) · 1.48 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def login(username, password) :
user_data = username + ":" + password + "\n"
try:
auth_data = open("start.auth", "r")
except FileNotFoundError :
print("Wrong Username or Password \n")
return False
auth_state = False
# print auth_data.readlines()
for auth in auth_data :
if user_data == auth :
print("Signed in")
auth_state = True
return auth_state
if auth_state != True :
print("Wrong Username or Password \n")
return False
auth_data.close()
def signup(username, password) :
user_data = [username + ":" + password, '\n']
auth_data = open("start.auth", "a")
auth_data.writelines(user_data)
print("\nRegistration complete \n \nYou can START next by placing your username and password as arguement \ne.g $ python start.py [username] [password] \noptional parameter menu=[option]\n")
auth_data.close()
return True
def check_user(username) :
try:
auth_data = open("start.auth", "r")
except FileNotFoundError :
return True
auth_state = False
for auth in auth_data :
auth = auth.replace("\n", "").split(":")
if auth[0] == username :
print("username already exist \n")
auth_state = False
break
else :
auth_state = True
if auth_state == False :
return False
else:
return True