-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.py
More file actions
31 lines (23 loc) · 769 Bytes
/
server.py
File metadata and controls
31 lines (23 loc) · 769 Bytes
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
import sqlite3
import hashlib
import socket
import threading
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("localhost", 9998))
server.listen()
def login(c):
c.send("Username: ".encode())
username = c.recv(1024).decode()
c.send("Password: ".encode())
password = c.recv(1024)
password = hashlib.sha256(password).hexdigest()
base = sqlite3.connect("data.db")
cursor = base.cursor()
cursor.execute("SELECT * FROM users WHERE username = ? AND password = ?", (username, password))
if cursor.fetchall():
c.send("Login successful!".encode())
else:
c.send("Login failed!".encode())
while True:
client, addr = server.accept()
threading.Thread(target=login, args=(client, )).start()