-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpc_client.py
More file actions
62 lines (46 loc) · 1.46 KB
/
pc_client.py
File metadata and controls
62 lines (46 loc) · 1.46 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
import sys
import hashlib as hl
from enum import Enum
import socket
class CODES(Enum):
OK_CODE = 400
ERROR_CODE = -300
class Profile:
def __init__(self,username,hashed_password):
self.username=username
self.hashed_password=hashed_password
def check_hash(self,hash_to_test)->bool:
if(hash_to_test==self.hashed_password):
return True
else:
return False
def login(connection):
sha256 = hl.sha256()
username = input("USERNAME\n")
sha256.update(input("PASSWORD\n").encode('utf-8'))
password = sha256.hexdigest()
session_profile = Profile(username, password)
#send profile info to the server
connection.send(username.encode("utf-8"))
connection.send(password.encode("utf-8"))
#receive reply from server to see if im logged or not
server_reply=connection.recv(1024).decode()
#checking the reply
if(server_reply==str(CODES.ERROR_CODE.value)):
print("PASSWORD DO NOT MATCH,RETRY")
login(connection)
else:
return session_profile
def connect_to_raspberry():
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect( ("127.0.0.1",5000))
return s
def setup():
with open("./setup.txt","r") as setupfile:
pass
if __name__=='__main__':
setup_parameters=setup()
connection=connect_to_raspberry()
session_profile=login(connection)
string="MONITOR_TH_MEASUREMENT"
connection.send(string.encode("utf-8"))