-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
113 lines (83 loc) · 3.88 KB
/
client.py
File metadata and controls
113 lines (83 loc) · 3.88 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# ===================== Imports ======================
import socket
import getpass
# ====================================================
# ===================== Setting Things up ======================
email = input("Enter your E-mail ID: ")
# ==============================================================
# ===================== Main Function ======================
def checkGrade(email):
# Connect to the client
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(("10.1.45.98", 8728))
# Send E-mail ID
clientsocket.send(email.encode())
response = clientsocket.recv(1024).decode()
# If server responds with 1, this E-mail address is not registered for the class
if response[0] == "1":
print("You are not registered for the class.")
# If server responds with 2, this E-mail address is registered for the class, and has an account
elif response[0] == "2":
# Enter password
secret = getpass.getpass("Enter your Password: ")
clientsocket.send(secret.encode())
response = clientsocket.recv(1024).decode()
# If password is incorrect, give the user the option to try again
if response[0] == "3":
print("Incorrect password.")
user_input = input("Try again?\nEnter y/n: ")
if user_input == "y":
clientsocket.close()
checkGrade(email)
return
# If password is correct, print the grade that the server sends
else:
print("Your latest score is: " + response)
# If server responds with 1, this E-mail address is registered for the class, but does not have an account
elif response[0] == "4":
# Give the user the option to create an account
print("Unregistered User. Create new account?")
user_input = input("Enter y/n: ")
# If user wants to create account
if user_input == "y":
clientsocket.send("y".encode())
# Enter and confirm password
response = clientsocket.recv(1024).decode()
secret = getpass.getpass("Create your password: ")
clientsocket.send(secret.encode())
response = clientsocket.recv(1024).decode()
secret = getpass.getpass("Enter your password again: ")
clientsocket.send(secret.encode())
response = clientsocket.recv(1024).decode()
secret = getpass.getpass("Enter OTP sent to your E-mail: ")
clientsocket.send(secret.encode())
response = clientsocket.recv(1024).decode()
# If all goes well and passwords match, account will be successfully created
# Send another request to check grade
if response[0] == "8":
print("Account successfully created!")
clientsocket.close()
checkGrade(email)
return
# If passwords don't match, give the user the option to try again
elif response[0] == "9":
print("Your passwords didn't match!")
user_input = input("Try again?\nEnter y/n: ")
if user_input == "y":
clientsocket.close()
checkGrade(email)
return
elif response[:2] == "10":
print("Your OTP is incorrect!")
user_input = input("Try again?\nEnter y/n: ")
if user_input == "y":
clientsocket.close()
checkGrade(email)
return
else:
clientsocket.send("n".encode())
# Exit
print("Exiting.")
clientsocket.close()
return
checkGrade(email)