This is a script for checking if any of the passwords you have stored in LastPass have been exposed through previous data breaches.
To use the script you need to have Python 3 installed and you need a CSV export of your LastPass vault. The export can be generated from the LastPass CLI with:
lpass export > lastpass.csv
or can be extracted with the browser plugin by going to the LastPass icon → More Options → Advanced → Export → LastPass CSV File (note that I did have problems getting this to work).
You can then run the above script on the file with:
python3 check-passwords.py lastpass.csv
or you can feed the passwords directly into the script from the LastPass CLI without writing them to disk by sending them to standard input:
lpass export | python3 check-passwords.py
Due to how the Pwned Passwords API works, the actual passwords will never leave your computer. A SHA1 checksum of the passwords will be generated and only the first 5 characters of that checksum will be sent to the API.
The script will print a line for each password found to be compromised along with the name of the site as saved in the vault along with the number of times the password has occurred in data breaches.
Thank you very much! Export from LastPass via browser plugin worked for me, however LastPass gives you a .html file. You have to copy and paste it from browser to e.g. Notepad++ and save it as .csv. See also here:
https://lastpass.com/support.php?cmd=showfaq&id=1206
Another problem is that the file is in UTF-8 and your script does not use UTF-8. I worked around this by extending line 11 like this:
with fileinput.input(openhook=fileinput.hook_encoded("utf-8")) as csvfile:
I hope this helps :-)