Ejemplo n.º 1
0
def test_new_branch():
    """
    Test the creation of a new branch with messages.
    """
    DB.init()
    assert DB.add_user("Ludwig")
    assert DB.add_user("Kevin")
    DB.init_chatt("Ludwig")
    Branch_id = DB.add_brach("Ludwig")
    assert Branch_id is not None
    assert DB.new_message("HEJ", "Ludwig", Branch_id, 0)
    assert DB.add_user_to_brach("Kevin", Branch_id)
    assert DB.new_message("Nej!", "Kevin", Branch_id, 1)
    assert DB.add_brach_summary(Branch_id, "Noob", "Kevin")
Ejemplo n.º 2
0
def test_new_chatt():
    """
    Test the creation of users and a shared chatsystem.
    """
    DB.init()
    assert DB.add_user("Ludwig")
    assert not DB.add_user("Ludwig")
    assert DB.add_user("Kevin", 2)
    branch_id = DB.init_chatt("Ludwig")
    assert branch_id is not None
    assert DB.set_user_role("Ludwig", 1)
    assert DB.delete_user("Ludwig")
    assert DB.get_chatt("Ludwig") == [branch_id]
    assert not DB.get_chatt("Kevin")
Ejemplo n.º 3
0
def test_user():
    """
    Test the creation and deletion of users, as well as changing att
    getting their roles.
    """
    DB.init()
    assert DB.add_user("Kevin")
    assert not DB.add_user("Kevin")
    assert DB.delete_user("Kevin")
    assert not DB.delete_user("Kevin")

    assert DB.add_user("Felicia", 2)
    assert DB.set_user_role("Felicia", 0)
    assert DB.get_user("Felicia") == ("Felicia", 0)
    assert not DB.set_user_role("Kevin", 7)
Ejemplo n.º 4
0
def test_messages():
    """
    Test adding diffrent types of messages
    Krav som testas: 6.2.1, 6.2.2
    """

    DB.init()
    assert DB.add_user("Ludwig")
    branch_id = DB.init_chatt("Ludwig")
    assert DB.new_message("HEJ", "Ludwig", branch_id, 0)
    assert DB.new_message("HEJ", "Kevin", branch_id, 1)
    assert not DB.new_message("HEJ", "Ludwig", branch_id + 1, 0)
    assert ["Ludwig", "HEJ", 0] in DB.get_messages(branch_id)
Ejemplo n.º 5
0
def test_brach_errors():
    """
    Test using whrong imputs for branches
    """

    DB.init()
    assert DB.add_user("Ludwig")
    branch_id = DB.init_chatt("Ludwig")
    assert not DB.init_chatt("Ludwig")
    assert not DB.init_chatt("Kevin")
    assert not DB.add_brach_summary(branch_id+1, "text", "Ludwig")
    assert not DB.add_user_to_brach("Kevin", branch_id)
    assert not DB.add_brach("Kevin")
Ejemplo n.º 6
0
def signup():
    '''The signup page for the application.
	Arguments:
		Nothing
	Returns:
		redirect(url_for("account_verification")): redirects user to the verification page on successful signup
		render_template("signup.html"): gets the signup.html file from the templates folder
	'''
    global verification_username
    if request.method == "POST":

        username = request.form["username"]
        password = request.form["password"]
        confirm = request.form["confirm"]
        email = request.form["email"]

        error = False

        if username == '':
            flash("Please enter a username", "username_error")
            error = True
        elif len(username) < 4:  #if length of username is less than 4
            flash("Username must be at least 4 characters", "username_error")
            #Categorizes the messsage into a category called "username_error"
            error = True
        elif len(username) > 25:  #if length of username is greater than 25
            flash("Username must not exceed 25 characters", "username_error")
            error = True
        elif " " in username:  #if the username contains any whitespaces
            flash("Username must not contain any spaces", "username_error")
            error = True
        elif db.check_username_already_used(username) == True:
            flash("Username is already being used", "username_error")
            error = True

        if password == '':
            flash("Please enter a password", "password_error")
            error = True
        elif len(password) < 8:
            flash("Password must be at least 8 characters long",
                  "password_error")
            error = True
        elif not any(char.isupper() for char in
                     password):  #if the password contains no uppercase letters
            flash("Password must contain at least 1 uppercase letter",
                  "password_error")
            error = True
        elif not any(char.islower() for char in
                     password):  #if the password contans no lowercase letters
            flash("Password must contain at least 1 lowercase letter",
                  "password_error")
            error = True
        elif not any(
                char.isdigit()
                for char in password):  #if the password contains no numbers
            flash("Password must contain at least 1 number", "password_error")
            error = True
        elif confirm != password:  #if the password does not match the other password the user entered
            flash("Passwords do not match", "password_error")
            error = True

        if email == '':
            flash("Please enter an email address", "email_error")
            error = True
        elif db.check_email_already_used(email) == True:
            flash("Email is already registed to an account", "email_error")
            error = True

        if error == False:
            hashed_password = hashing.hash_password(username, password)
            db.add_user(username, hashed_password, email, 0)
            session["verificationusername"] = username
            return redirect(url_for("account_verification"))

    return render_template("signup.html")
Ejemplo n.º 7
0
def main():
    if not path.exists('passwords.db'):
        create_database()

    while True:
        option = main_menu()

        if option not in ['l', 's', 'd', 'e']:
            print('Invalid option\n')

        elif option == 'e':
            exit()

        elif option == 's':
            #  Create new user
            print('''I will need some informations. DO NOT FORGET OR YOU WILL
                    LOSE ACCESS TO ALL YOUR PASSWORDS\n''')

            #  Check if username is valid
            users_list = get_usernames_list()
            valid = False
            while not valid:
                username = input('\nWhat is your username? ')
                for name in users_list:
                    if username == name[0]:
                        print('\nUsername alredy taken')
                        break
                else:
                    valid = True

            master_password = input('\nWhat is your master password? ')
            master_hashed = get_hash(master_password)
            key = generate_key()

            try:
                add_user(username, master_hashed, key)
                print('\nUser added successully!')
            except sqlite3.Error:
                print('\nAn error ocurred, try again later')

        elif option == 'l':
            username = input('\nWhat is your username? ')
            provided_password = input('\nWhat is your master password? ')
            provided_hashed = str(get_hash(provided_password))

            accessed = check_user(username, provided_hashed)

            if accessed:
                print(f'\nWellcome {username}\n')
                user_id = get_user_id(username)
                user_key = get_key(user_id)

                while True:
                    operation = user_menu()

                    if operation not in ['l', 'a', 'g', 'u', 'd', 'e']:
                        print('\nInvalid option!')

                    elif operation == 'e':
                        print(f'\nGoodbye {username}!\n')
                        break

                    elif operation == 'l':
                        services_list = list_saved_services(user_id)

                        if len(services_list) == 0:
                            print("\nThere are no services yet\n")
                        else:
                            print('\nOkay, listing services...\n')
                            for i in range(len(services_list)):
                                print(
                                    f'Service {i + 1}: {services_list[i][0]}\n'
                                )

                    elif operation == 'a':
                        #  Check if service isn't alredy saved
                        services_list = list_saved_services(user_id)
                        valid = False
                        while not valid:
                            service_name = input(
                                '\nWhat is the name of the service? ')
                            for service in services_list:
                                if service_name == service[0]:
                                    print("\nService alredy registered")
                                    break
                            else:
                                valid = True

                        username = input(
                            f"\nWhat is your username in {service_name}? ")
                        password = input(
                            f'\nWhat is your password in {service_name}? ')
                        encrypted_password = encrypt_password(
                            user_key, password)

                        add_service(service_name, username, encrypted_password,
                                    user_id)

                        print('\nService added successfully!')

                    elif operation == 'g':
                        service = input(
                            '\nWhat service do you want to check? ')
                        service_list = list_saved_services(user_id)

                        for existing_service in service_list:
                            if service == existing_service[0]:
                                exists = True
                                break
                        else:
                            exists = False

                        if not exists:
                            print('\nThis is not a registered service')
                        else:
                            username, hashed_password = check_data_from_service(
                                user_id, service)

                            password = decrypt_password(
                                user_key, hashed_password)

                            print(
                                f'\nService: {service}\nUsername: {username}\nPassword: {password}'
                            )

                    elif operation == 'u':
                        service = input(
                            '\nWhat is the service you want to update? ')

                        service_list = list_saved_services(user_id)

                        for name in service_list:
                            if name[0] == service:
                                exists = True
                                break
                        else:
                            exists = False

                        if exists:
                            username = input(
                                '\nWhat will be your new username? (press enter for no changing) '
                            )
                            password = input(
                                '\nWhat will be your new password? (press enter for no changing) '
                            )

                            if username == '' and password == '':
                                print('\nYou must change at least one!')
                                continue

                            elif username == '':

                                encrypted_password = encrypt_password(
                                    user_key, password)
                                update_service_password(
                                    user_id, service, encrypted_password)

                            elif password == '':
                                update_service_username(
                                    user_id, service, username)

                            elif username != '' and password != '':
                                encrypted_password = encrypt_password(
                                    user_key, password)
                                update_service_password(
                                    user_id, service, encrypted_password)
                                update_service_username(
                                    user_id, service, username)

                            print('\nService updated successfully!')

                        else:
                            print("\nThis service isn't registred")

                    elif operation == 'd':
                        service = input(
                            '\nWhat is the service you want to delete? ')

                        service_list = list_saved_services(user_id)

                        for name in service_list:
                            if name[0] == service:
                                exists = True
                                break
                        else:
                            exists = False

                        if exists:
                            delete_service(user_id, service)
                            print('\nService deleted successfully!')

                        else:
                            print("\nThis service isn't registred")

            elif accessed is False:
                print('\nAccess denied!')

            elif accessed is None:
                print('\nUser not found')

        elif option == 'd':
            username = input('\nWhat is your username? ')
            provided_password = input('\nWhat is your master password? ')
            provided_hashed = str(get_hash(provided_password))

            accessed = check_user(username, provided_hashed)

            if accessed:
                user_id = get_user_id(username)
                delete_user(user_id)
                print(f'\nThe user {username} was deleted successfully')

            elif accessed is False:
                print('\nAccess denied!')

            elif accessed is None:
                print("\nThis user doesn't exists")
Ejemplo n.º 8
0
    def send(self):
        """
        Send data from QLineEdit
        """

        if self.state == ApplicationStates.SIGN_UP:
            self.provided_username = self.username.text()
            self.provided_password = self.password.text()

            if self.provided_username == '' or self.provided_password == '':
                self.warning.setText(
                    'You must type in a username and a password!')
                self.warning.show()
                return

            users_list = get_usernames_list()
            for name in users_list:
                if self.provided_username == name[0]:
                    self.warning.setText('Username alredy taken')
                    self.warning.show()
                    return

            else:
                key = generate_key()
                master_hashed = get_hash(self.provided_password)
                try:
                    add_user(self.provided_username, master_hashed, key)
                    self.info.setText('User registered successully')
                    self.info.show()
                    self.main_menu()
                except sqlite3.Error:
                    self.warning.setText('A problem occurred, try again later')
                    self.warning.show()

        elif self.state == ApplicationStates.LOGIN:

            self.provided_username = self.username.text()
            self.provided_password = self.password.text()

            if self.provided_username == '' or self.provided_password == '':
                self.warning.setText(
                    'You must type in a username and a password!')
                self.warning.show()
                return

            provided_hash = str(get_hash(self.provided_password))

            #  Checking if user exists
            users_list = get_usernames_list()

            for user in users_list:
                if self.provided_username == user[0]:
                    if provided_hash == get_master_hashed(self.provided_username):
                        accessed = True
                        break
                    else:
                        accessed = False
                        break
            else:
                accessed = None

            if accessed:
                self.reset_widgets()
                self.user_id = get_user_id(self.provided_username)
                self.user_key = get_key(self.user_id)
                self.header.setText(f'Welcome {self.provided_username}')
                self.list_button.show()
                self.add_service_button.show()
                self.get_data_button.show()
                self.update_service_button.show()
                self.delete_service_button.show()
                self.delete_user_button.show()
                self.logoff_button.show()

            elif accessed is False:
                self.warning.setText('Access denied!')
                self.warning.show()

            elif accessed is None:
                self.warning.setText('User not found')
                self.warning.show()

        elif self.state == ApplicationStates.ADD_SERVICE:
            service_name = self.service_name.text()
            service_username = self.username.text()
            service_password = self.password.text()

            if service_name == '' or service_username == '' or service_password == '':
                self.warning.setText('All fields are required')
                self.warning.show()
                return

            else:
                services_list = list_saved_services(self.user_id)
                for service in services_list:
                    if service_name == service[0]:
                        self.warning.setText('Service alredy registered')
                        self.warning.show()
                        return

                else:
                    encrypted_password = encrypt_password(
                        self.user_key, service_password)
                    add_service(service_name, service_username,
                                encrypted_password, self.user_id)
                    self.info.setText('Service added successfully')
                    self.info.show()
                    self.cancel()

        elif self.state == ApplicationStates.CHECK_SERVICE:
            service_name = self.service_name.text()

            if service_name == '':
                self.warning.setText('You must type in the service name!')
                self.warning.show()
                return

            services_list = list_saved_services(self.user_id)

            for service in services_list:
                if service_name == service[0]:
                    service_exists = True
                    break
            else:
                service_exists = False

            if not service_exists:
                self.warning.setText('This is not a registered service')
                self.warning.show()

            else:
                username, password = check_data_from_service(
                    self.user_id, service_name)
                password = decrypt_password(self.user_key, password)
                self.info.setText(
                    f'Service: {service[0]}\nUsername: {username}\nPassword: {password}')
                self.info.show()
                self.cancel()

        elif self.state == ApplicationStates.UPDATE_SERVICE:
            service_name = self.service_name.text()
            username = self.username.text()
            password = self.password.text()

            if service_name == '' or (username == '' and password == ''):
                self.warning.setText(
                    'You must choose the service name and at least one of the others!')
                self.warning.show()
                return

            services_list = list_saved_services(self.user_id)

            for name in services_list:
                if name[0] == service_name:
                    service_exists = True
                    break
            else:
                service_exists = False

            if not service_exists:
                self.warning.setText('This is not a registered service')
                self.warning.show()

            else:
                if username == '':
                    encrypted_password = encrypt_password(
                        self.user_key, password)
                    update_service_password(
                        self.user_id, service_name, encrypted_password)

                elif password == '':
                    update_service_username(self.user_id, service_name, username)

                elif username != '' and password != '':
                    encrypted_password = encrypt_password(
                        self.user_key, password)
                    update_service_password(
                        self.user_id, service_name, encrypted_password)
                    update_service_username(
                        self.user_id, service_name, username)

                self.info.setText('Service updated successfully!')
                self.info.show()
                self.cancel()

        elif self.state == ApplicationStates.DELETE_SERVICE:
            service_name = self.service_name.text()

            if service_name == '':
                self.warning.setText('You must type in the service name!')
                self.warning.show()
                return

            services_list = list_saved_services(self.user_id)

            for service in services_list:
                if service_name == service[0]:
                    service_exists = True
                    break
            else:
                service_exists = False

            if not service_exists:
                self.warning.setText('This is not a registered service')
                self.warning.show()

            else:
                delete_service(self.user_id, service_name)
                self.info.setText(
                    f'Service {service_name} was deleted successfully!')
                self.info.show()
                self.cancel()