forked from Karamax/PCS.2
/
users.py
76 lines (59 loc) · 2.04 KB
/
users.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
73
74
75
import json
import os
import socket
import json
import tkinter
from tkinter import simpledialog as sd
from tkinter import *
root = Tk()
work = True
sock = socket.socket()
sock.connect(('localhost',7070))
def addUser():
print('Enter username')
#username = input()
username = sd.askstring("Enter username:", "Enter username")
print('Enter password')
#password = input()
password = sd.askstring("Enter password:", "Enter password")
import hmac, hashlib
password = hmac.new(bytearray('signature', 'utf-8'), bytearray(password, 'utf-8'), hashlib.sha256).hexdigest()
uData = {'Operation': 'add', 'Login': username, 'Password': password}
sendData(uData)
return
def removeUser():
print('Enter username')
username = sd.askstring("Enter username:", "Enter username")
uData = {'Operation': 'remv', 'Login': username}
sendData(uData)
return
def changePass():
print('Enter username')
username = sd.askstring("Enter username:", "Enter username")
print('Enter new password')
password = sd.askstring("Enter password:", "Enter password")
import hmac, hashlib
password = hmac.new(bytearray('signature', 'utf-8'), bytearray(password, 'utf-8'), hashlib.sha256).hexdigest()
uData = {'Operation': 'chan', 'Login': username, 'Password': password}
sendData(uData)
return
def wrongId():
print('Wrong input.')
sd.messagebox.showerror('Error', 'Wrong operation id')
return
def exitProg():
global work
work = False
uData = {'Operation': 'exit'}
sendData(uData)
sock.close()
return
def sendData(data):
sock.send(json.dumps(data).encode())
data = sock.recv(1024)
sd.messagebox.showinfo('Status', data.decode())
while work:
print('Select operation: 1 - add, 2 - remove, 3 - change password, 4 - exit program')
operationId = sd.askstring("Select operation:", " 1 - add, 2 - remove, 3 - change password, 4 - exit program")
operation = {'1': addUser, '2': removeUser, '3': changePass, '4': exitProg}
operation.get(operationId, wrongId)()