Browse Source

added random password generator

master
Holger Frey 2 years ago
parent
commit
63e8203e81
  1. 1
      pyproject.toml
  2. 27
      work_helpers/password.py

1
pyproject.toml

@ -26,3 +26,4 @@ xls2pylist = "work_helpers.excel2pylist:cli" @@ -26,3 +26,4 @@ xls2pylist = "work_helpers.excel2pylist:cli"
sg_mbp_release = "work_helpers.sg_mbp_release:sg_mbp_release"
sg_mbp_new_version = "work_helpers.sg_mbp_release:sg_mbp_new_version"
sg_list_frms = "work_helpers.sg_frm_list:cli"
random_password = "work_helpers.password:get_random_password"

27
work_helpers/password.py

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
from email.policy import default
import click
import itertools
import random
import pyperclip
lowers = "abcdefghijklmnopqrstuvwxyz"
uppers = lowers.upper()
decimals = "0123456789"
characters = list(lowers + uppers + decimals)
@click.command()
@click.option("--length", default=16, type=int)
def get_random_password(length=16):
""" generates a random password and copies it to the clipboard """
choice = [random.choice(characters) for i in range(length)]
groups = [iter(choice)] * 4
grouped = ("".join(g) for g in itertools.zip_longest(*groups, fillvalue=""))
password = "-".join(grouped)
pyperclip.copy(password)
click.echo("Copied to clipboard:", err=True)
click.echo(password)
Loading…
Cancel
Save