Total Complexity | 6 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import getpass |
||
2 | import sys |
||
3 | |||
4 | |||
5 | def create_password( |
||
6 | journal_name: str, prompt: str = "Enter password for new journal: " |
||
7 | ) -> str: |
||
8 | while True: |
||
9 | pw = getpass.getpass(prompt) |
||
10 | if not pw: |
||
11 | print("Password can't be an empty string!", file=sys.stderr) |
||
12 | continue |
||
13 | elif pw == getpass.getpass("Enter password again: "): |
||
14 | break |
||
15 | |||
16 | print("Passwords did not match, please try again", file=sys.stderr) |
||
17 | |||
18 | if yesno("Do you want to store the password in your keychain?", default=True): |
||
19 | from .EncryptedJournal import set_keychain |
||
20 | |||
21 | set_keychain(journal_name, pw) |
||
22 | return pw |
||
23 | |||
24 | |||
25 | def yesno(prompt, default=True): |
||
26 | prompt = f"{prompt.strip()} {'[Y/n]' if default else '[y/N]'} " |
||
27 | response = input(prompt) |
||
28 | return {"y": True, "n": False}.get(response.lower().strip(), default) |
||
29 |