コード例 #1
0
    def register(self, gui, username, password, sec_question, sec_answer):
        if (username and password):
            if (len(password) < 8):
                """
                Displays a pop up if username is not available.
                Clears both textboxes to enter new information.
                """
                tkinter.messagebox.showinfo(
                    "Warning", "Password must be at least 12 characters long!")
                self.usernameInput.delete(0, 'end')
                self.passwordInput.delete(0, 'end')
                self.sec_answerInput.delete(0, 'end')
                self.sec_questionInput.delete(0, 'end')
                # Clear these out since certain parameters are persistent objects?
                username = ""
                password = ""
                sec_question = ""
                sec_answer = ""
            elif (re.search(r"\d", password) is None):
                """
                Displays a pop up if username is not available.
                Clears both textboxes to enter new information.
                """
                tkinter.messagebox.showinfo("Warning",
                                            "Password must contain a number!")
                self.usernameInput.delete(0, 'end')
                self.passwordInput.delete(0, 'end')
                self.sec_answerInput.delete(0, 'end')
                self.sec_questionInput.delete(0, 'end')
                # Clear these out since certain parameters are persistent objects?
                username = ""
                password = ""
                sec_question = ""
                sec_answer = ""
            elif (re.search(r"[A-Z]", password) is None):
                """
                Displays a pop up if username is not available.
                Clears both textboxes to enter new information.
                """
                tkinter.messagebox.showinfo(
                    "Warning", "Password must contain an uppercase letter!")
                self.usernameInput.delete(0, 'end')
                self.passwordInput.delete(0, 'end')
                self.sec_answerInput.delete(0, 'end')
                self.sec_questionInput.delete(0, 'end')
                # Clear these out since certain parameters are persistent objects?
                username = ""
                password = ""
                sec_question = ""
                sec_answer = ""
            elif (re.search(r"[a-z]", password) is None):
                """
                Displays a pop up if username is not available.
                Clears both textboxes to enter new information.
                """
                tkinter.messagebox.showinfo(
                    "Warning", "Password must contain a lowercase letter!")
                self.usernameInput.delete(0, 'end')
                self.passwordInput.delete(0, 'end')
                self.sec_answerInput.delete(0, 'end')
                self.sec_questionInput.delete(0, 'end')
                # Clear these out since certain parameters are persistent objects?
                username = ""
                password = ""
            elif (re.search(r"[!#$%&'()*+,-./]", password) is None):
                """
                Displays a pop up if username is not available.
                Clears both textboxes to enter new information.
                """
                tkinter.messagebox.showinfo(
                    "Warning", "Password must contain a special character!")
                self.usernameInput.delete(0, 'end')
                self.passwordInput.delete(0, 'end')
                self.sec_answerInput.delete(0, 'end')
                self.sec_questionInput.delete(0, 'end')
                # Clear these out since certain parameters are persistent objects?
                username = ""
                password = ""
                sec_question = ""
                sec_answer = ""
            else:
                # CODE NEEDED: Encrypt Password
                response = gui.getClient().register(username, password,
                                                    sec_question, sec_answer)
                """
                Checks to see if username is available.
                """
                if (response == 0):
                    """
                    Displays a pop up if username is not available.
                    Clears both textboxes to enter new information.
                    """
                    tkinter.messagebox.showinfo(
                        "Warning",
                        "Account already exist with that username. Please enter another one."
                    )
                    self.usernameInput.delete(0, 'end')
                    self.passwordInput.delete(0, 'end')
                    # Clear these out since certain parameters are persistent objects?
                    username = ""
                    password = ""
                    sec_question = ""
                    sec_answer = ""
                else:
                    """
                    Creates a new account.
                    Clears both textboxes.
                    Takes the user to the menu page.
                    """
                    print("Account created")
                    self.usernameInput.delete(0, 'end')
                    self.passwordInput.delete(0, 'end')
                    # Clear these out since certain parameters are persistent objects?
                    username = ""
                    password = ""
                    sec_question = ""
                    sec_answer = ""
                    gui.show_frame(menu.MenuPage)

                    # Checks to see if client didn't enter a password.
        elif (username):
            tkinter.messagebox.showinfo("Warning", "Please enter a password.")

            # Checks to see if client didn't enter a username.
        elif (password):
            tkinter.messagebox.showinfo("Warning", "Please enter a username.")

            # Checks to see if client didn't enter any information.
        else:
            tkinter.messagebox.showinfo(
                "Warning", "Please enter a username and password.")
コード例 #2
0
    def login(self, gui, username, password):
        # parameter: gui -> The GUI that is being used.
        # parameter: username -> The username the client provided.
        # parameter: password -> The password the client provided.
        """
		Checks to see if client entered information for both
		the username and password fields.
		"""
        if (username and password):

            # CODE NEEDED: Encrpty password
            response = gui.getClient().login(username, password)
            """
			Checks to see if the there is any problems with loginning.
			"""
            if (response == -1):
                tkinter.messagebox.showinfo("Warning",
                                            "Server failed to respond!")
                """
				Empties the textboxes to reenter information.
				"""
                self.usernameInput.delete(0, 'end')
                self.passwordInput.delete(0, 'end')
                # Clear these out since certain parameters are persistent objects?
                username = ""
                password = ""
            elif (response == 0):
                tkinter.messagebox.showinfo("Warning",
                                            "Invalid login information.")
                """
				Empties the textboxes to reenter information.
				"""
                self.usernameInput.delete(0, 'end')
                self.passwordInput.delete(0, 'end')
                # Clear these out since certain parameters are persistent objects?
                username = ""
                password = ""
            else:
                """
				Empties the textboxes.
				"""
                print("Login Successfully")
                self.usernameInput.delete(0, 'end')
                self.passwordInput.delete(0, 'end')
                # Clear these out since certain parameters are persistent objects?
                username = ""
                password = ""
                gui.show_frame(menu.MenuPage)

        # Checks to see if client didn't enter a password.
        elif username:
            tkinter.messagebox.showinfo("Warning", "Please enter a password.")

        # Checks to see if client didn't enter a username.
        elif (password):
            tkinter.messagebox.showinfo("Warning", "Please enter a username.")

        # Checks to see if client didn't any login information.
        else:
            tkinter.messagebox.showinfo(
                "Warning", "Please enter a username and password.")