Holger Frey
2 years ago
2 changed files with 28 additions and 0 deletions
@ -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…
Reference in new issue