forked from rctorr/PythonMexico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenpass-0.3.py
executable file
·46 lines (36 loc) · 1.23 KB
/
genpass-0.3.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
44
45
46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import click
import random
@click.command()
@click.option("--len", default=8, type=int, help="Longitud de la clave")
@click.option("--n", default=1, type=int,
help="Indica el número de claves a generar")
@click.option("--with-simb", is_flag=True,
help="Indica si se incluyen los símbolos como parte de la clave, por omosión no.")
def genpass(len, n, with_simb):
"""
Genera una clave segura usando como base el alfabeto inglés en
mayúsculasx, minúsculas y digitos.
"""
minusculas = "abcdefghijklmnopqrstuvwxyz"
mayusculas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
digitos = "01234567890"
simbolos = "!@#$%&()=+-:;.,"
for i in range(n):
clave = random.choice(minusculas)
clave += random.choice(mayusculas)
clave += random.choice(digitos)
k = len - 3
alfabeto = minusculas+mayusculas+digitos
if with_simb:
clave += random.choice(simbolos)
alfabeto += simbolos
k -= 1
faltan = random.choices(alfabeto, k=k)
clave = list(clave) + faltan
random.shuffle(clave)
clave = "".join(clave)
print(clave)
if __name__ == "__main__":
genpass()