Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SERVER
- import socket
- import hashlib
- def PWcheck():
- global data
- f= open("passwords.txt")
- f1=f.readlines()
- if password in f1:
- print("Login successfull")
- ls = ("login successfull")
- c.send(ls.encode())
- elif password != f1:
- print("Password incorrect")
- ls = ("Password incorrect")
- c.send(ls.encode())
- recive()
- def recive():
- global password
- password = c.recv(1024).decode()#reciving the password
- print("Password from client: ", password)
- PWcheck()
- def menu():
- message = ("Welcome to the system. Press 1 to register, 2 to login.")
- c.send(message.encode())
- recive()
- def listening():
- print("Listening")
- global data
- data = s.recv(1024).decode()
- def sending(text):
- global data
- data = c.sendall(text.encode())
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- print("Listening: ")
- s.bind(('127.0.0.1', 4000))
- s.listen(10) #listen to 1 connection at a time
- c, addr = s.accept()
- print ("Connection from: ", addr)
- menu()
- c.close()
- input("\n\n press enter to close")
- #########################################################################
- CLIENT
- import socket
- import hashlib
- import os
- import os, sys
- from stat import *
- cwd = os.getcwd() #current working directory
- def hashPW(password): #take a password, hashing it then saving it in a database
- return hashlib.sha256(str.encode(password)).hexdigest()
- def register():
- password = str(input("Please choose a password: "))
- message = hashPW(password)
- print("Password created.")
- f= open("passwords.txt","a")#creates a file for the password
- f.write('\n'+ message)
- f.close()
- login()
- def login():
- password = str(input("Please enter your password to login: "))
- message = hashPW(password)
- s.send(message.encode())
- ls = (s.recv(1024))
- if ls ==("login successfull"):
- print(ls)
- select()
- else:
- print(ls)
- login()
- def select():
- select = s.recv(1024)
- print(select)
- if select ==1:
- file_check()
- elif select ==2:
- email()
- def email_message():
- print("this will be email once ian gets to it")
- def file_write():
- pass
- def file_check():
- print("Current directory: ", os.getcwd())
- print("")
- print("Type ", '{:<30}'.format("File name"), "Size of file (Bytes)")
- print("---- ", '{:<30}'.format("---------"), "-"*20)
- for file in os.listdir("."):
- # get details of file
- try:
- a=os.stat(file)
- if( S_ISDIR(a.st_mode) ):
- print("<dir> ", file)
- else:
- print("<file> ", '{:<30}'.format(file), a.st_size)
- except:
- print(file, " <<unable to access>>")
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- print("Waiting for connection")
- s.connect(('127.0.0.1', 4000))
- data = s.recv(1024).decode()#max number of bytes recv
- print (data)
- choice = int(input("Please input your choice"))
- if choice == 1:
- register()
- elif choice == 2:
- login()
- elif choice == 3:
- file_check()
- s.close()
- input("\n\n press enter to close")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement