def log(): global user, newpass choice = sign.sign() if (choice == "1"): user = sign.login(user) encrypt = input("Do you want to encrypt your password? (Y/N)") if encrypt == "Y": print("Your information has been encrypted") affine = crypt.Affine() user["password"] = affine.encrypt(user["password"]) s.send(bytes("login", "utf-8")) msg = pickle.dumps(user) s.send(msg) user["password"] = affine.decrypt(user["password"]) else: print("You choose not to encrypt your password.") s.send(bytes("login", "utf-8")) msg = pickle.dumps(user) s.send(msg) elif (choice == "2"): encrypt = input("Do you want to encrypt your password? (Y/N)") if (encrypt == "N"): user = sign.regis(user) s.send(bytes("regis", "utf-8")) elif (encrypt == "Y"): user = sign.regisAndEncrypt(user) s.send(bytes("regis_encrypt", "utf-8")) msg = pickle.dumps(user) s.send(msg) elif (choice == "3"): user = sign.unlogin_changePassword(user) newpass = getpass("New password >> ") encrypt = input("Do you want to encrypt your password? (Y/N)") if encrypt == "Y": affine = crypt.Affine() newpass = affine.encrypt(newpass) s.send(bytes("unlogin_cpass_encrypt", "utf-8")) else: s.send(bytes("unlogin_cpass", "utf-8")) msg = pickle.dumps(user) s.send(msg) else: s.send(bytes("quit", "utf-8"))
def changePass(): global user newPass = sign.changePassword(user) if newPass == False: return False encrypt = input("Do you want to encrypt your password? (Y/N)") if encrypt == "Y": affine = crypt.Affine() user["password"] = affine.encrypt(user["password"]) s.send(bytes("newpass_encrypt", "utf-8")) else: s.send(bytes("newpass", "utf-8")) msg = pickle.dumps(user) s.send(msg)
def check_user_login(user): count = 0 for x in user_data["username"]: if user["username"] == x: #print(x) #print(user_data.at[count, 'password']) affine = crypt.Affine() if (user["password"] == user_data.at[count, 'password']) or (affine.decrypt( user["password"]) == user_data.at[count, 'password']): print(user_data.at[count, 'status'] == "online") if user_data.at[count, 'status'] == "online": return "000" user_data.loc[count, 'status'] = "online" memory.update({user["username"]: count}) print(user_data) print(memory) return True count += 1 return False
def run(self): print("Connection from: ", self.caddress) while (True): print("Server waiting for message") data = self.csocket.recv(numByteReceive) if (data.decode("utf-8") == "cli_accept"): print("Client " + clients[self.csocket] + " is going to handle_chat") self.handle_chat() #QUIT STATUS if (data.decode("utf-8") == "quit"): self.csocket.send(bytes("exit", "utf8")) self.csocket.close() break elif (data.decode("utf-8") == "login_quit"): self.csocket.send(bytes("in_exit", "utf8")) #ur = self.csocket.recv(numByteReceive) txt = clients[self.csocket] clients.pop(self.csocket) address.pop(self.csocket) user_data.loc[memory[txt], 'status'] = "off" self.csocket.close() break elif (data.decode("utf-8") == "log_out"): self.csocket.send(bytes("log_out_success", "utf8")) #ur = self.csocket.recv(numByteReceive) txt = clients[self.csocket] user_data.loc[memory[txt], 'status'] = "off" print(user_data) else: print("From client ", self.caddress, " content:", data.decode("utf-8")) #QUIT STATUS #HANDLE_LOGIN_REGIS if (data.decode("utf-8") == "regis"): msg = self.csocket.recv(4098) userdata = pickle.loads(msg) #print("Message: ", userdata) if check_user_regis(userdata): self.csocket.send(bytes("regis_success", "utf-8")) else: self.csocket.send(bytes("regis_fail", "utf-8")) elif (data.decode("utf-8") == "regis_encrypt"): msg = self.csocket.recv(4098) userdata = pickle.loads(msg) affine = crypt.Affine() userdata["password"] = affine.decrypt(userdata["password"]) if check_user_regis(userdata): self.csocket.send(bytes("regis_success", "utf-8")) else: self.csocket.send(bytes("regis_fail", "utf-8")) elif (data.decode("utf-8") == "login"): msg = self.csocket.recv(4098) userdata = pickle.loads(msg) if check_user_login(userdata) == True: self.csocket.send(bytes("success", "utf-8")) clients[self.csocket] = userdata["username"] print("\nCLIENTS: ", clients) print("\nADDR: ", address) elif check_user_login(userdata) == "000": self.csocket.send(bytes("000", "utf-8")) else: self.csocket.send(bytes("login_fail", "utf-8")) #HANDLE_LOGIN_REGIS #CHANGE PASSWORD if (data.decode("utf-8") == "newpass"): msg = self.csocket.recv(4098) userdata = pickle.loads(msg) handle_changepass(userdata) self.csocket.send(bytes("log_cp_200", "utf-8")) elif (data.decode("utf-8") == "newpass_encrypt"): msg = self.csocket.recv(4098) userdata = pickle.loads(msg) affine = crypt.Affine() userdata["password"] = affine.decrypt(userdata["password"]) handle_changepass(userdata) self.csocket.send(bytes("log_cp_200", "utf-8")) elif (data.decode("utf-8") == "unlogin_cpass"): msg = self.csocket.recv(4098) userdata = pickle.loads(msg) if check_user_cpass(userdata): self.csocket.send(bytes("cpass_200", "utf-8")) obj = self.csocket.recv(4098) newpass = pickle.loads(obj) handle_unlogin_cpass(newpass) self.csocket.send( bytes(">> Change password successfully", "utf-8")) else: self.csocket.send(bytes("cpass_404", "utf-8")) elif (data.decode("utf-8") == "unlogin_cpass_encrypt"): msg = self.csocket.recv(4098) userdata = pickle.loads(msg) if check_user_cpass(userdata): self.csocket.send(bytes("cpass_200", "utf-8")) obj = self.csocket.recv(4098) newpass = pickle.loads(obj) affine = crypt.Affine() newpass["password"] = affine.decrypt(newpass["password"]) handle_unlogin_cpass(newpass) self.csocket.send( bytes(">> Change password successfully", "utf-8")) else: self.csocket.send(bytes("cpass_404", "utf-8")) #CHANGE PASSWORD #CHECK USER if (data.decode("utf-8") == "check_user"): self.csocket.send(bytes("accept_ch_us", "utf-8")) msg = self.csocket.recv(4098) userdata = pickle.loads(msg) check = find_user(userdata) if check == "False": self.csocket.send(bytes("user_404", "utf-8")) else: rep = option_check(userdata, check) if userdata["option"] == "-show_all": self.csocket.send(bytes("user_obj", "utf-8")) msg = pickle.dumps(rep) self.csocket.send(msg) elif rep == False: self.csocket.send(bytes("err_option", "utf-8")) self.csocket.send(bytes(userdata["option"], "utf-8")) else: self.csocket.send(bytes(rep, "utf-8")) #CHECK USER #SETUP INFO if (data.decode("utf-8") == "set_info"): msg = self.csocket.recv(4098) userdata = pickle.loads(msg) result = handle_setup_info(userdata) if result == True: self.csocket.send(bytes("set_success", "utf-8")) else: self.csocket.send(bytes("set_fail", "utf-8")) self.csocket.send(bytes(result, "utf-8")) #SETUP INFO #CHAT if (data.decode("utf-8") == "chat"): user = self.csocket.recv(numByteReceive).decode("utf-8") pack = {"username": user} pos = find_user(pack) if len(chat_list) >= 2: self.csocket.send(bytes("join_chat_fail", "utf-8")) else: if pos == "False": self.csocket.send(bytes("chat_user_404", "utf-8")) else: if check_user_online(user, pos): clisocket = find_clisocket_in_clients_byname(user) chat_list.update({ self.csocket: clients[self.csocket], clisocket: user }) print("Chat List: ", chat_list) clisocket.send(bytes("chat_req", "utf-8")) self.csocket.send(bytes("chat_user_onl", "utf-8")) print("Client 1 is going into handle_chat") self.handle_chat() print("DEBUG: Client 1 out chatroom") else: self.csocket.send(bytes("chat_user_off", "utf-8")) mes = user + " is offline" self.csocket.send(bytes(mes, "utf-8")) #CHAT #HANDEL FILE if (data.decode("utf-8") == "download"): self.csocket.send(bytes("down_acpt", "utf-8")) filename = self.csocket.recv(numByteReceive).decode("utf-8") self.download(filename) elif (data.decode("utf-8") == "upload"): self.csocket.send(bytes("upload_acpt", "utf-8")) filename = self.csocket.recv(numByteReceive).decode("utf-8") self.upload(filename) #HANDLE FILE print("Client at ", self.caddress, " disconnected...")
def cree(): affine = cr.Affine() passw = "sdqwdas123" enpass = affine.encrypt(passw) print(affine.encrypt(passw)) print(affine.decrypt(enpass))