-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkpasswd.py
43 lines (30 loc) · 997 Bytes
/
mkpasswd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import click
import string
import random
def get_chars(symbols):
all_chars = string.ascii_letters + string.digits
if symbols:
all_chars = all_chars + string.punctuation
all_chars = list(all_chars)
random.shuffle(all_chars)
return all_chars
def generate_password(length=16, symbols=False):
""" Generate a strong password """
characters = get_chars(symbols)
parts = []
for i in range(length):
parts.append(random.choice(characters))
return "".join(parts)
@click.command()
@click.option("--symbols", "-s", is_flag=True)
@click.option("--length", "-l", default=16)
@click.option("--quiet", "-q", is_flag=True)
def cli(symbols, length, quiet):
""" Make strong passwords """
pw = generate_password(length=length, symbols=symbols)
if quiet:
click.secho(pw)
return
click.secho(f"--- Generating a strong password of length {length} ---", fg="green")
click.secho(pw)
click.secho("---", fg="green")