Skip to content

Instantly share code, notes, and snippets.

@trnila
Created April 25, 2017 19:07
Show Gist options
  • Save trnila/26625a5a8018400d383687419db4b8d3 to your computer and use it in GitHub Desktop.
Save trnila/26625a5a8018400d383687419db4b8d3 to your computer and use it in GitHub Desktop.
Check your passwords in chromium for strength
import sqlite3
import string
import passwordmeter
from termcolor import colored
import secrets
import pyperclip
import os
import tempfile
import shutil
def generate(length=20):
chars = string.ascii_letters + string.digits + ' ' * 10 + string.punctuation
password = ''
for i in range(length):
password += chars[secrets.token_bytes(1)[0] % len(chars)]
return password
temp = tempfile.NamedTemporaryFile()
shutil.copyfile(os.path.expanduser('~/.config/chromium/Default/Login Data'), temp.name)
c = sqlite3.connect(temp.name)
for row in c.execute('select origin_url, username_value, password_value from logins'):
url, user, password = row
password = password.decode('utf-8')
strength, tips = passwordmeter.test(row[2].decode('utf-8'))
if strength > 0.5:
pass
print(colored("Site {} has weak password: {} ({})".format(url, password, strength), 'red'))
for tip, message in tips.items():
print(" {}".format(message))
if input('press space to copy better password to clipboard and go to the web, other key to skip ') == ' ':
new = generate()
pyperclip.copy(new)
os.system("xdg-open {}".format(url))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment