示例#1
0
    def login(self, username, password):
        """Takes the login information, ecrypts it, and prepares it to be sent to the server."""

        connection = self.sock
        connection.send("login".encode())
        status_code = connection.recv(2)
        if status_code != client_api.SUCCESS:
            print("Failled")
            return 0

        register = loginEncryption.LoginEncoding()
        register.setUsername(username)
        register.setPassword(password)
        username = register.getUsername()
        password = register.getPassword()

        login_info = "username:"******";password:" + password

        connection.send(login_info.encode())

        server_response = connection.recv(2)  # SUCCESS or FAILURE
        print(server_response.decode())
        if server_response == client_api.SUCCESS:
            repoids.clear()
            packed_repo_id = connection.recv(4)
            repo_id_tup = struct.unpack('<L', packed_repo_id)
            repo_id = repo_id_tup[0]
            repoids.append(repo_id)
            print(repo_id)
        else:
            return 0

        global_username.clear()
        global_username.append(username)
        return 1
示例#2
0
    def register(self, username, password, sec_question, sec_answer):
        """Takes the parameters, hashes the password, encodes the username, and prepares it to be sent to server"""

        if self.connected == False:
            return 0
        connection = self.sock
        connection.send("register".encode())

        register = loginEncryption.LoginEncoding()
        register.setUsername(username)
        register.setPassword(password)
        username = register.getUsername()
        password = register.getPassword()

        register_info = "username:"******";password:"******";sec_question:" \
                        + sec_question + ";sec_answer:" + sec_answer
        connection.send(register_info.encode())
        server_response = connection.recv(2)
        if server_response == client_api.SUCCESS:
            repoids.clear()
            packed_repo_id = connection.recv(4)
            repo_id_tup = struct.unpack('<L', packed_repo_id)
            repo_id = repo_id_tup[0]
            repoids.append(repo_id)
            print(repo_id)
        else:
            return 0

        global_username.clear()
        global_username.append(username)
        return 1
示例#3
0
    def login(self, username, password):
        connection = self.sock
        connection.send("login".encode())
        print("Hello")
        status_code = connection.recv(2)
        print("MSG Replayed")
        if status_code != client_api.SUCCESS:
            print("Failled")
            return 0

        login_info = "username:"******";" + "password:" + password

        # print(login_info)

        connection.send(login_info.encode())
        # self.sock.send(login_info.encode())
        # connection.close()
        server_response = connection.recv(2)  # SUCCESS or FAILURE
        print(server_response.decode())
        if server_response == client_api.SUCCESS:
            repoids.clear()
            packed_repo_id = connection.recv(4)
            repo_id_tup = struct.unpack('<L', packed_repo_id)
            repo_id = repo_id_tup[0]
            repoids.append(repo_id)
            print(repo_id)
            return 1
        else:
            return 0
    def createGroup(self, group, members):
        connection = self.sock

        connection.send("create_group".encode())

        status_code = connection.recv(2)

        if status_code != SUCCESS:
            print("Error")
            return -1
        message = []
        message.append("gname:")
        message.append(group)
        message.append(";")
        message.append("members:")
        for i in members:
            message.append(i)
            message.append(",")
        if members:
            message.pop()
        message = ''.join(message)
        message = message.encode()
        connection.send(message)
        result = connection.recv(2)
        if result != SUCCESS:
            return -1

        packed_gid = connection.recv(4)
        gid = struct.unpack("<L", packed_gid)
        repoids.append(gid)
        return 1
示例#5
0
    def createGroup(self, group, members):
        """
        Takes the name of a group, and iterates through a list of usernames to add to the group.
        :param group: string
        :param members: list
        :return:
        """
        connection = self.sock

        connection.send("create_group".encode())

        status_code = connection.recv(2)

        if status_code != SUCCESS:
            print("Error")
            return -1
        message = []
        message.append("gname:")
        message.append(group)
        message.append(";")
        message.append("members:")
        for i in members:
            message.append(i)
            message.append(",")
        if members:
            message.pop()
        message = ''.join(message)
        message = message.encode()
        connection.send(message)
        result = connection.recv(2)
        if result != SUCCESS:
            return -1

        packed_gid = connection.recv(4)
        gid = struct.unpack("<L", packed_gid)
        repoids.append(gid)
        return 1
示例#6
0
    def register(self, username, password):
        if self.connected == False:
            return 0  # Maybe change to a unique code stating we are not connected?
        connection = self.sock
        connection.send("register".encode())

        # credentials = LoginEncoding(username, password)
        # username = credentials.getUsername()
        # password = credentials.getPassword()
        # key = credentials.getKey()

        register_info = "username:"******";" + "password:" + password
        connection.send(register_info.encode())
        server_response = connection.recv(2)
        if server_response == client_api.SUCCESS:
            repoids.clear()
            packed_repo_id = connection.recv(4)
            repo_id_tup = struct.unpack('<L', packed_repo_id)
            repo_id = repo_id_tup[0]
            repoids.append(repo_id)
            print(repo_id)
            return 1
        else:
            return 0