diff --git a/pyproject.toml b/pyproject.toml index d03f488..f4ff9d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/work_helpers/password.py b/work_helpers/password.py new file mode 100644 index 0000000..014b71c --- /dev/null +++ b/work_helpers/password.py @@ -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) + \ No newline at end of file