-
Notifications
You must be signed in to change notification settings - Fork 13
/
user_input.py
86 lines (65 loc) · 2.81 KB
/
user_input.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from getpass import getpass
from lastpass import exceptions
from utils import get_lastpass_vault
def _user_lastpass_username():
return input("Enter your LastPass email: ")
def _user_lastpass_password():
return getpass("Enter your LastPass password: ")
def _user_lastpass_multifactor_password():
lastpass_multifactor_password = input("If you are using 2FA, enter your code (or press enter to skip this step):")
return lastpass_multifactor_password or None
def _user_get_lastpass_vault():
print("Hello this is HaveIBeenPwned for your LastPass vault.")
print("First we need to log you in to your LastPass account, so we'll need your credentials.")
retry = 'y'
while retry == 'y':
lastpass_username = _user_lastpass_username()
lastpass_password = _user_lastpass_password()
lastpass_multifactor_password = _user_lastpass_multifactor_password()
print("Now we'll try to log you in!")
try:
vault = _user_login_lastpass(lastpass_username, lastpass_password, lastpass_multifactor_password)
break
except exceptions.Error as e:
print("Couldn't log you in due to an error: {}".format(e))
retry = input("Retry with some new credentials? y/n")
else:
input("Press any key to exit.")
sys.exit()
return vault
def _user_login_lastpass(username, password, multifactor_password=None):
try:
try:
vault = get_lastpass_vault(username, password, multifactor_password)
except exceptions.LastPassUnknownUsernameError:
username = _user_lastpass_username()
password = _user_lastpass_password()
raise
except exceptions.LastPassInvalidPasswordError:
password = _user_lastpass_password()
raise
except (exceptions.LastPassIncorrectGoogleAuthenticatorCodeError, exceptions.LastPassIncorrectYubikeyPasswordError):
multifactor_password = _user_lastpass_multifactor_password()
raise
except exceptions.Error:
vault = get_lastpass_vault(username, password, multifactor_password)
return vault
def _user_get_mode():
print("There are multiple modes available: ")
print("1 - Check all your passwords.")
print("2 - Check all your usernames on specific domains.")
print("* - Run all of the above one by one.")
modes = {'1': ['check_password'], '2': ['check_username'], '*': ['check_password', 'check_username']}
choices = '/'.join(k for k in modes.keys())
while True:
print()
mode = input("Enter the number of your choice ({}): ".format(choices))
if mode in modes:
mode = modes[mode]
break
else:
print("Incorrect mode chosen, retry!")
return mode