Exemple #1
0
    def test_delete_credential(self):
        """
        Test if we can remove a credential account from our credential list.
        """

        self.new_credential.save_credentials()
        test_credential = Credentials("Snapchat", "test43", "wordpass")
        test_credential.save_credentials()
        Credentials.delete_credential("Snapchat")
        self.assertEqual(len(Credentials.credential_list), 1)
Exemple #2
0
def main():
    print("Hello, welcome to Password Manager")
    while True:
        print("\nPlease use these short codes to execute your desired task: ca - create new account, li - login to account, ex - exit program")
        
        short_code = input().lower().strip()

        if short_code == "ca":
            fname = input("Enter your first name: ").strip()
            lname = input("Enter your last name: ").strip()
            username = input("Enter your preferred username: "******"\nThat username has already been taken. Please enter a different username.")
                username = input("Enter your preferred username: "******"Enter your password: "******"\nYour new account has been created with the following details:\nName: {fname} {lname}\nUsername: {username}\nPassword: {password}\n")

        elif short_code == "li":
            print("\nPlease enter your user details to login.")
            login_username = input("Enter your username: "******"Enter your password: "******"\nHello {login_username}, please use the following codes to select a task.")
                while True:
                    print("\ncc - Create Credentials\ndelc - Delete Credential\ndc -Display Credentials\ndsc - Display Specific Credential\nex - Exit")
                    code = input().lower().strip()

                    if code == "cc":
                        app = input("\nEnter the name of the app: ")
                        credential_username = input("Enter your username: "******"\nUse the following options to select which password you prefer\ncp - Custom Password\nap - Auto-Generated Password\nex - Exit")
                            option = input().lower().strip()

                            if option == "cp":
                                credential_password = input("\nEnter your password: "******"ap":
                                credential_password = Credentials.password()
                                break
                            elif option == "ex":
                                break
                            else:
                                print("\nInvalid input. Check options and try again.")
                    
                        new_credential = create_credentials(app, credential_username, credential_password)
                        new_credential.save_credentials()

                        print(f"\nNewly created credential details:\nApp Name: {app}\nUsername: {credential_username}\nPassword: {credential_password}")

                    elif code == "delc":
                        delete_app = input("\nEnter the app name of the credential you wish to delete: ")
                        Credentials.delete_credential(delete_app)
                        print(f"{delete_app} Credentials has been deleted.")

                    elif code == "dc":
                        if Credentials.display_credentials():
                            for credential in Credentials.display_credentials():
                                print(f"\nApp: {credential.app}\nUsername: {credential.username}\nPassword: {credential.password}\n")
                        else:
                            print("\nYou haven't created any credentials yet.")

                    elif code == "dsc":
                        app_credential = input("\nEnter app name of the credential you wish to be displayed: ")

                        credential_information = Credentials.display_app_credential(app_credential)

                        if credential_information:
                            print(f"\nApp: {credential_information.app}\nUsername: {credential_information.username}\nPassword: {credential_information.password}")
                        else:
                            print("\nThat credential cannot be found. Please try again")
                    
                    elif code == "ex":
                        break
                        
                    else:
                        print("\nInvalid input. Please check the code and try again.")

        elif short_code == "ex":
            break

        else:
            print("\nInvalid input. Please check your entry and try again.")
Exemple #3
0
def del_credential(credential):
    '''
  Deletes a credential from the account

  '''
    Credentials.delete_credential(credential)
class TestCredentials(unittest.TestCase):
    def setUp(self):
        self.new_credential = Credentials("Bree95", "Facebook", "password1")

    def tearDown(self):
        Credentials.credentials_list = []

    def test_init(self):
        '''
    Test case to test if the object is initialized properly

    '''
        self.assertEqual(self.new_credential.user_name, "Bree95")
        self.assertEqual(self.new_credential.account_name, "Facebook")
        self.assertEqual(self.new_credential.password, "password1")

    def test_save_credentials(self):
        '''
    Test case to test if the credentials object is saved into the credentials list

    '''
        self.new_credential.save_credentials()
        self.assertEqual(len(Credentials.credentials_list), 1)

    def test_save_multiple_credentials(self):
        '''
    Test case to check is we can save multiple credentials objects to the credentials_list

    '''
        self.new_credential.save_credentials()
        test_credential = Credentials("Brenda", "gmail", "4676jl")
        test_credential.save_credentials()
        self.assertEqual(len(Credentials.credentials_list), 2)

    def test_delete_credentials(self):
        '''
    Test case to test if user can remove credential from credentials list.
    
    '''
        self.new_credential.save_credentials()
        test_credential = Credentials("Brenda", "gmail", "4676jl")
        test_credential.save_credentials()
        self.new_credential.delete_credential()
        self.assertEqual(len(Credentials.credentials_list), 1)

    def test_find_by_account_name(self):
        '''
    Test to check whether we can find a credential by its name and display information

    '''
        self.new_credential.save_credentials()
        test_credential = Credentials('Brenda', 'gmail', '4676jl')
        test_credential.save_credentials()
        found_credential = Credentials.find_by_account_name('gmail')
        self.assertEqual(found_credential.account_name,
                         test_credential.account_name)

    def test_copy_credential(self):
        '''
    Test to check if user can copy the right credentials
    
    '''
        self.new_credential.save_credentials()
        test_credential = Credentials('Brenda', 'gmail', '4676jl')
        test_credential.save_credentials()
        find_credential = None
        for credential in Credentials.credentials_list:
            find_credential = Credentials.find_by_account_name(
                credential.account_name)
            return pyperclip.copy(find_credential.password)
        self.assertEqual('4676jl', pyperclip.paste())
        print(pyperclip.paste())