| @@ -23,12 +23,12 @@ Usage: |
| 23 | Run this script in your terminal to access these functions. |
23 | Run this script in your terminal to access these functions. |
| 24 | """ |
24 | """ |
| 25 | |
25 | |
| 26 | from account import Account |
| |
| 27 | import database |
| |
| 28 | from string import ascii_letters, punctuation, digits |
26 | from string import ascii_letters, punctuation, digits |
| 29 | import random |
27 | import random |
| 30 | import uuid |
28 | import uuid |
| 31 | from prettytable import PrettyTable |
29 | from prettytable import PrettyTable |
| |
30 | from account import Account |
| |
31 | import database |
| 32 | |
32 | |
| 33 | |
33 | |
| 34 | def generate_characters(n: int) -> list: |
34 | def generate_characters(n: int) -> list: |
| @@ -78,7 +78,8 @@ def generate_passphrase(n: int, sep: str) -> str: |
| 78 | phrases = [] |
78 | phrases = [] |
| 79 | lucky_number = random.choice(range(0, n)) |
79 | lucky_number = random.choice(range(0, n)) |
| 80 | for _ in range(n): |
80 | for _ in range(n): |
| 81 | line = random.choice(open('wordlist.txt').readlines()) |
81 | with open('wordlist.txt', 'r', encoding='utf-8') as file: |
| |
82 | line = random.choice(file.readlines()) |
| 82 | line = line.replace('\n', '') |
83 | line = line.replace('\n', '') |
| 83 | if _ == lucky_number: |
84 | if _ == lucky_number: |
| 84 | phrases.append(line.strip().capitalize() + str(_)) |
85 | phrases.append(line.strip().capitalize() + str(_)) |
| @@ -102,17 +103,17 @@ def list_accounts() -> None: |
| 102 | print(t) |
103 | print(t) |
| 103 | |
104 | |
| 104 | |
105 | |
| 105 | def delete_account(uuid: str) -> None: |
106 | def delete_account(account_uuid: str) -> None: |
| 106 | """ |
107 | """ |
| 107 | Deletes an account by its UUID. |
108 | Deletes an account by its UUID. |
| 108 | |
109 | |
| 109 | Args: |
110 | Args: |
| 110 | uuid (str): The UUID of the account to delete |
111 | account_uuid (str): The UUID of the account to delete |
| 111 | |
112 | |
| 112 | Returns: |
113 | Returns: |
| 113 | None |
114 | None |
| 114 | """ |
115 | """ |
| 115 | account_record = database.find_account(uuid) |
116 | account_record = database.find_account(account_uuid) |
| 116 | account = Account(account_record[0][0], |
117 | account = Account(account_record[0][0], |
| 117 | account_record[0][1], |
118 | account_record[0][1], |
| 118 | account_record[0][2], |
119 | account_record[0][2], |
| @@ -130,7 +131,8 @@ def purge_accounts() -> None: |
| 130 | None |
131 | None |
| 131 | """ |
132 | """ |
| 132 | check = input( |
133 | check = input( |
| 133 | 'Are you absolutely sure you want to delete your password vault? This action is irreversible. (y/n): ') |
134 | '''Are you absolutely sure you want to delete your password vault? |
| |
135 | This action is irreversible. (y/n): ''') |
| 134 | if check.lower() == 'y': |
136 | if check.lower() == 'y': |
| 135 | database.purge_table() |
137 | database.purge_table() |
| 136 | database.purge_database() |
138 | database.purge_database() |
| @@ -174,7 +176,7 @@ def create_account() -> None: |
| 174 | if password_length < 8: |
176 | if password_length < 8: |
| 175 | print('Error: Your password length must be at least 8 characters.') |
177 | print('Error: Your password length must be at least 8 characters.') |
| 176 | return |
178 | return |
| 177 | password_string = generate_password(password_length) |
179 | password_string = generate_password(password_length) # pylint: disable=undefined-variable |
| 178 | else: |
180 | else: |
| 179 | password_string = input('Please enter your desired password: ') |
181 | password_string = input('Please enter your desired password: ') |
| 180 | |
182 | |
| @@ -185,16 +187,17 @@ def create_account() -> None: |
| 185 | |
187 | |
| 186 | |
188 | |
| 187 | |
189 | |
| 188 | def edit_account(uuid: str, edit_parameter: int) -> None: |
190 | def edit_account(account_uuid: str, edit_parameter: int) -> None: |
| 189 | """ |
191 | """ |
| 190 | Allow users to edit any account information except the UUID. |
192 | Allow users to edit any account information except the UUID. |
| 191 | |
193 | |
| 192 | Args: |
194 | Args: |
| 193 | uuid (str): Unique identifier of the account. |
195 | account_uuid (str): Unique identifier of the account. |
| 194 | edit_parameter (int): Parameter indicating which field to edit. |
196 | edit_parameter (int): Parameter indicating which field to edit. |
| 195 | Valid values are 1 for application name, 2 for username, |
197 | Valid values are 1 for application name, 2 for username, |
| 196 | 3 for password, and 4 for URL. |
198 | 3 for password, and 4 for URL. |
| 197 | """ |
199 | """ |
| |
200 | field_name, new_value = '' |
| 198 | if edit_parameter == 1: |
201 | if edit_parameter == 1: |
| 199 | field_name = 'application' |
202 | field_name = 'application' |
| 200 | new_value = input('Please enter your desired Application name: ') |
203 | new_value = input('Please enter your desired Application name: ') |
| @@ -218,5 +221,5 @@ def edit_account(uuid: str, edit_parameter: int) -> None: |
| 218 | elif edit_parameter == 4: |
221 | elif edit_parameter == 4: |
| 219 | field_name = 'url' |
222 | field_name = 'url' |
| 220 | new_value = input('Please enter your desired URL: ') |
223 | new_value = input('Please enter your desired URL: ') |
| 221 | database.update_account(field_name, new_value, uuid) |
224 | database.update_account(field_name, new_value, account_uuid) |
| 222 | print('Account successfully updated.') |
225 | print('Account successfully updated.') |