-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.py
72 lines (63 loc) · 2.96 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from funcs import *
def login():
try:
f = open("auth.csv", "r+") # Open the CSV storing the usernames and passwords in read-only mode
except FileNotFoundError:
print("Please sign up first!")
pause()
return("", "")
found1 = False
found2 = False
while not found1: # Checks if the user is successfully logged in
user1 = str(input("Enter Player 1 username: "))
pass1 = str(input("Enter Player 1 password: "))
userpass1 = user1 + ", " + pass1 + "\n"
for line in f.readlines(): # Moves the read-head down a line
if(line == userpass1): # Checks if current line is the same as the username and password
print("\nWelcome, " + user1 + "\n")
found1 = True # Declares the user as logged in
break # Stops the program for searching further down the list
if not found1 :
print("\nPlease try again\n")
f.seek(0) # Sets the read-head to the start of the file
while not found2: # Repeates process for the second user
f.seek(0) # Sets the read-head to the start of the file
user2 = input("Enter Player 2 username: ")
pass2 = input("Enter Player 2 password: ")
userpass2 = user2 + ", " + pass2 + "\n"
for line in f.readlines():
if(line == userpass2) and (userpass2 != userpass1):
print("\nWelcome, " + user2 + "\n")
found2 = True
break
if not found2 and (userpass2 == userpass1): # Checks if the second user is the same as the first
print("Player 2 cannot be the same as Player 1")
f.seek(0)
elif not found2 :
print("\nPlease try again\n")
f.seek(0)
return(user1, user2) # Sends the name of both users to the main program
def sign_up():
f = open("auth.csv", "a+") # Open the CSV storing the usernames and passwords in read mode to verify the username hasn't already been used
Valid = False
Valid2 = True
while not Valid:
user = str(input("Enter Desired Username: "))
passw = str(input("Enter Desired Password: "))
userpass = user + ", " + passw + "\n"
for line in f.readlines(): # Moves the read-head down a line
temp = line.split(",") # Splits the username-password combination
userline = temp[0] # Removes the password
if(userline == user): # Compares the chosen username with the existing one
print("Desired Username is already user")
Valid = False
Valid2 = False
f.seek(0)
break
else:
Valid2 = True
if Valid2:
f.close()
f = open("auth.csv", "a") # Switches to file append mode
f.write(userpass) # Appends chosem username-password combination
Valid = True