Ejemplo n.º 1
0
def delete_entry_from_db(connection):
    identifier = input(
        "Enter the identifier of the entry you wish to delete: ").strip()
    try:
        with connection:
            en = None
            cursor = connection.cursor()
            cursor.execute('SELECT * FROM login WHERE identifier = ?',
                           (identifier, ))
            en = cursor.fetchall()
            if en:
                slow_type("\nEntry Found.\n")
                display_entry(en[0])
                while True:
                    delete = input(
                        'Are you sure you wish to delete this entry? [Y/N] ')
                    if delete == 'Y':
                        slow_type("\nDeleting entry........\n")
                        cursor.execute(
                            "DELETE FROM login WHERE identifier = ?",
                            (identifier, ))
                        slow_type("Entry successfully deleted.\n")
                        return
                    elif delete == 'N':
                        return
                    else:
                        slow_type("Invalid response. Select Y or N.\n")
            else:
                slow_type("\nNo entry found with identifier: {}\n".format(
                    identifier))
    except sqlite3.OperationalError as operror:
        print(operror)
    return
Ejemplo n.º 2
0
def display_all_entries(connection):
    try:
        with connection:
            cursor = connection.cursor()
            cursor.execute('SELECT * FROM login')
            entries = cursor.fetchall()
            slow_type("\nFound {} entries in database.\n".format(len(entries)))
            for entry in entries:
                display_entry(entry)
    except sqlite3.OperationalError as operror:
        print(operror)
Ejemplo n.º 3
0
def decrypt_entry(*args):
    decrypted_entries = []
    generate_key()
    f = Fernet(KEY)
    for arg in args:
        try:
            darg = f.decrypt(arg)
            decrypted_entries.append(darg.decode("utf-8"))
        except InvalidToken as iserror:
            print(iserror)
            slow_type("Error: Incorrect passkey.\nExiting.......")
            sys.exit()
    return tuple(decrypted_entries)
Ejemplo n.º 4
0
def get_entry_from_db(connection):
    identifier = input(
        "Enter the identifier of the entry you wish to retrieve: ")
    entry = None
    try:
        cursor = connection.cursor()
        cursor.execute('SELECT * FROM login WHERE identifier = ?',
                       (identifier, ))
        entry = cursor.fetchall()
    except sqlite3.OperationalError as operror:
        print(operror)
    if entry:
        slow_type("...............\n", typing_speed=400, random_speed=False)
        slow_type("Entry Found:\n")
        display_entry(entry[0])
        while True:
            modify = input("Would you like to modify this entry? [Y/N] ")
            if modify == 'Y':
                change_entry(connection, identifier)
            elif modify == 'N':
                return
            else:
                print("Invalid response.\n")
    else:
        slow_type("...............\n", typing_speed=400, random_speed=False)
        slow_type("Entry Not Found.\n")
def main():
    attempts = 0
    while attempts < 3:
        if passutils.password_check(passutils.get_password()):
            slow_type("Access Granted.\n")
            actions()
        else:
            slow_type("Access Denied.\n")
            attempts += 1
            if attempts > 0:
                slow_type("{} more attempt(s) left.\n".format(
                    passutils.MAX_ATTEMPTS - attempts))
    slow_type("Maximum attempts reached.\nExiting...\n")
    sys.exit()
Ejemplo n.º 6
0
def commit_entry_to_db(connection, entry):
    try:
        with connection:
            cursor = connection.cursor()
            ids = None
            cursor.execute('SELECT identifier FROM login')
            ids = cursor.fetchall()
            if entry[0] not in format_response(ids):
                cursor.execute(
                    """
                    INSERT INTO login(identifier,username,password,lastmodified)
                    VALUES(?,?,?,?)
                """, entry)
                return True
            else:
                slow_type(
                    "\nAn entry with the identifier {} already exists.".format(
                        entry[0]))
                slow_type("Identifiers must be unique.\n")
                return False
    except sqlite3.OperationalError as operror:
        print(operror)
    return False
def actions():
    while True:
        slow_type("\nChoose Action:\n")
        slow_type("\t[1] Create new entry.")
        slow_type("\t[2] Retrieve entry.")
        slow_type("\t[3] Delete entry.")
        slow_type("\t[4] Display all entries.")
        slow_type("\t[5] Exit.\n")
        action = int(input("--> "))
        if action in [1, 2, 3, 4]:
            # actionable actions
            connection = dbutils.connect_to_db(dbutils.DB_FILENAME)
            dbutils.create_table(connection)
            if action == 1:
                entry = dbutils.create_entry()
                if dbutils.commit_entry_to_db(connection, entry):
                    slow_type("\nEntry successfully added.\n")
            elif action == 2:
                dbutils.get_entry_from_db(connection)
            elif action == 3:
                dbutils.delete_entry_from_db(connection)
            elif action == 4:
                dbutils.display_all_entries(connection)
        elif action == 5:
            slow_type("\nExiting...\n")
            sys.exit()
        else:
            slow_type("Invalid Action.\n")
Ejemplo n.º 8
0
def display_entry(entry):
    decrypted_entry = decrypt_entry(entry[1], entry[2], entry[3])
    slow_type("\n\tIdentifier: {}".format(entry[0]))
    slow_type("\tUsername: {}".format(decrypted_entry[0]))
    slow_type("\tPassword: {}".format(decrypted_entry[1]))
    slow_type("\tLast Modified: {}\n".format(decrypted_entry[2]))
Ejemplo n.º 9
0
def change_entry(connection, identifier):
    while True:
        slow_type("\nWhat attribute(s) would you like to change?\n")
        slow_type("\t[1] Username")
        slow_type("\t[2] Password")
        slow_type("\t[3] No change\n")
        field_to_change = int(input("--> "))
        if field_to_change == 1 or field_to_change == 2:
            try:
                with connection:
                    cursor = connection.cursor()
                    if field_to_change == 1:
                        newname = getpass("Enter new username: "******"""
                            UPDATE login 
                            SET username = ? 
                            WHERE identifier = ?;
                        """, (*encrypt_entry(newname), identifier))
                    else:
                        newpass = getpass("Enter new password: "******"""
                            UPDATE login 
                            SET password = ? 
                            WHERE identifier = ?;
                        """, (*encrypt_entry(newpass), identifier))
                    last_update = datetime.now().strftime("%H:%M:%S;%m/%d/%Y")
                    cursor.execute(
                        """
                        UPDATE login 
                        SET lastmodified = ? 
                        WHERE identifier = ?;
                    """, (*encrypt_entry(last_update), identifier))
            except sqlite3.OperationalError as operror:
                print(operror)
            slow_type("Entry successfully updated.\n")
        elif field_to_change == 3:
            return
        else:
            slow_type("Invalid field. Please select [1], [2], or [3].")
    return