-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgenpass-0.2.py
More file actions
executable file
·36 lines (28 loc) · 929 Bytes
/
Copy pathgenpass-0.2.py
File metadata and controls
executable file
·36 lines (28 loc) · 929 Bytes
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
#!/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")
def genpass(len, n):
"""
Genera una clave segura usando como base el alfabeto inglés en
mayúsculasx, minúsculas y digitos.
"""
minusculas = "abcdefghijklmnopqrstuvwxyz"
mayusculas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
digitos = "01234567890"
for i in range(n):
clave = random.choice(minusculas)
clave += random.choice(mayusculas)
clave += random.choice(digitos)
k = len - 3
faltan = random.choices(minusculas+mayusculas+digitos, k=k)
clave = list(clave) + faltan
random.shuffle(clave)
clave = "".join(clave)
print(clave)
if __name__ == "__main__":
genpass()