-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathexample.py
More file actions
executable file
·39 lines (30 loc) · 1.14 KB
/
example.py
File metadata and controls
executable file
·39 lines (30 loc) · 1.14 KB
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
#!/usr/bin/env python
# coding: utf-8
from __future__ import print_function
import json
import os
from lastpass import (
Vault,
LastPassIncorrectYubikeyPasswordError,
LastPassIncorrectGoogleAuthenticatorCodeError
)
DEVICE_ID = "example.py"
with open(os.path.join(os.path.dirname(__file__), 'credentials.json')) as f:
credentials = json.load(f)
username = credentials['username']
password = credentials['password']
try:
# First try without a multifactor password
vault = Vault.open_remote(username, password, None, DEVICE_ID)
except LastPassIncorrectGoogleAuthenticatorCodeError as e:
# Get the code
multifactor_password = input('Enter Google Authenticator code:')
# And now retry with the code
vault = Vault.open_remote(username, password, multifactor_password, DEVICE_ID)
except LastPassIncorrectYubikeyPasswordError as e:
# Get the code
multifactor_password = input('Enter Yubikey password:')
# And now retry with the code
vault = Vault.open_remote(username, password, multifactor_password, DEVICE_ID)
for index, i in enumerate(vault.accounts):
print("{} {}".format(index + 1, str(i)))