def change_password_info(self) -> None: result = self.find_app_and_username('What is the app whose information you want change?') if not result: return # show password info obtain_password(result, False) # ask user what should be changed # print('\n') while True: new_data = get_changed_info() new_line = list(result) for i, key in enumerate(('username', 'email', 'placeholder', 'app_name', 'url')): if key in new_data: new_line[i+1] = new_data[key] print_info('The following information will be updated in the database:', new_line[1:]) ans = yes_or_no_question('Do you want to proceed?') if ans == 'y': self.pm.update_password_data(result[0], new_data) print('Information has been updated.') return else: ans2 = yes_or_no_question('Do you want to try again?') if ans2 == 'n': print('Updating cancelled.\n') return
def change_password_in_db_or_not(self, db_line: tuple[int, str, str, str, str, str]) -> bool: answer = yes_or_no_question('Do you want to save this password to the database?') if answer == 'y': print_info('The following information will be updated in the database:', db_line[1:]) answer2 = yes_or_no_question('Do you want to proceed?') if answer2 == 'y': self.pm.change_password(db_line[0], db_line[3]) print('Password has been updated.') return True if answer2 == 'n': print('Changing password canceled.') return True if answer == 'n': answer2 = yes_or_no_question('Do you want to generate new password again?') if answer2 == 'y': return False if answer2 == 'n': print('Changing password canceled.') return True
def get_unique_info_from_user(self) -> Optional[tuple[str, str, str, str]]: while True: # info = (username, email, app, url) info = get_info_from_user() if not(self.pm.find_password(info[2], True, info[0])): return info print(f'Password for user {info[0]} to app {info[2]} already in database.') ans = yes_or_no_question('Do you want to try again?') if ans == 'n': # return empty list if user does not want to try again return None
def delete_password(self) -> None: result = self.find_app_and_username('What is the app whose password you want to delete') if not result: return print_info('The following information will be deleted from the database:', result[1:]) ans = yes_or_no_question('Do you want to delete this information?') if ans == 'y': self.pm.delete_password(result[0]) print('Password has been deleted from the database.') if ans == 'n': print('Delete process cancelled.\n')
def __init__(self, existing_and_not_default: bool =False, waiting_time: int =20) -> None: self.timeout = waiting_time self.pm = connect_to_pm_dbs(False, False) if not self.pm: print('Normal files not found.') if not existing_and_not_default: self.pm = connect_to_pm_dbs(True, False) if self.pm: a = yes_or_no_question('Do you want to use default files?') if a.lower() == 'n': self.pm = None if not self.pm: ans = yes_or_no_question('Do you want to initialize the Password Manager?') if ans.lower() == 'y': print('Initializing Password Manager databases...') self.pm = connect_to_pm_dbs(True, True) print('Password database initialized.') master_password = get_master_password() self.pm.add_master_password(master_password) self.pm.set_name_lists()
def save_password_to_db_or_not(self, info: tuple[str, str, str, str, str]) -> bool: answer = yes_or_no_question('Do you want to save this password to the database?') if answer == 'y': print_info('The following information will be saved to the database:', info) answer2 = yes_or_no_question('Do you want to proceed?') if answer2 == 'y': self.pm.force_add_password(*info) print(f'Password for user {info[0]} to app {info[3]} has been saved to the database.') return True if answer2 == 'n': answer3 = yes_or_no_question('Do you want to generate password again?') if answer3 == 'y': return False if answer3 == 'n': print('Adding password canceled.') return True if answer == 'n': answer2 = yes_or_no_question('Do you want to generate password again?') if answer2 == 'y': return False if answer2 == 'n': print('Adding password canceled.') return True
def test_yes_or_no_question(self, monkeypatch, ans1, ans2, result): # with mock.patch('builtins.input', return_value='Y'): # assert pm_ui_fcns.yes_or_no_question('blah') == 'y' count = [0] def answer(question=None): if 'Y/N' in question: count[0] += 1 if count[0] == 1: return ans1 return ans2 return None monkeypatch.setattr('builtins.input', answer) assert pm_ui_fcns.yes_or_no_question('big question?') == result