-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.py
More file actions
83 lines (67 loc) · 2.22 KB
/
Copy pathuser.py
File metadata and controls
83 lines (67 loc) · 2.22 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
from db_operations import insert_user_values, fetch_user_data, delete_user_rows, check_user_password, insert_session_values, if_logged_in, logout_session
from time import sleep
import socket
import getpass
import secrets
import subprocess
import sys
from client import main as client
from server import main as server
def generate_session_id():
return secrets.token_hex(16)
def expire_session_id():
pass
def login():
print("Type EXIT at username to quit the app")
username = input("Enter Username-> ")
if username == 'EXIT':
print("Exiting.... ")
sleep(1)
sys.exit()
password = getpass.getpass("Enter your password: ")
print("Authenticating......")
sleep(2)
if check_user_password(username, password) == True:
print("Authenticated!")
print(f"Welcome {username.split(' ')[0]}!!")
print(":)")
insert_session_values(generate_session_id(), username)
else:
print("Invalid Credentials")
print("Please Try Again")
return username
def dashboard(username):
while True:
try:
number = int(input("Enter 0 to chat with a user, print 1 to logout-> "))
if number == 0:
chat(username)
elif number == 1:
logout(username)
else:
print("Invalid Request")
except ValueError:
print("Invalid Input! Enter only numbers")
def isServerRunning(host, portno):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect((host, portno)) == 0
def chat(username):
client(username)
def logout(username):
sleep(1)
print("Logging out.......")
logout_session(username)
login()
def register():
print("Please enter your credentials-> ")
while True:
username = input("Enter Username-> ")
password = getpass.getpass("Enter your password: ")
password_confirm = getpass.getpass("Confirm your password: ")
if password != password_confirm:
print("The password is not the same. Please try again")
else:
break
insert_user_values(username, password)
print("Succesfully made a new account!")
print("Please Log in")