forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
DanielR
committed
Nov 18, 2023
1 parent
d529989
commit f8900b0
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
Retos/Reto #3 - EL GENERADOR DE CONTRASEÑAS [Media]/python/danielzx9.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
'''``` | ||
/* | ||
* Escribe un programa que sea capaz de generar contraseñas de forma aleatoria. | ||
* Podrás configurar generar contraseñas con los siguientes parámetros: | ||
* - Longitud: Entre 8 y 16. | ||
* - Con o sin letras mayúsculas. | ||
* - Con o sin números. | ||
* - Con o sin símbolos. | ||
* (Pudiendo combinar todos estos parámetros entre ellos) | ||
*/ | ||
``` | ||
''' | ||
|
||
import string | ||
import random | ||
|
||
def contra(longitudContra, mayus, numeros, simbol): | ||
caracteres = string.ascii_lowercase | ||
if mayus: | ||
caracteres += string.ascii_uppercase | ||
if numeros: | ||
caracteres += string.digits | ||
if simbol: | ||
caracteres += string.punctuation | ||
|
||
contrasena = ''.join(random.choice(caracteres) for _ in range(longitudContra)) | ||
return contrasena | ||
|
||
def main(): | ||
longitudContra = int(input("Ingrese la longitud que desea para la contraseña (entre 8 y 16): ")) | ||
if not (8 <= longitudContra <= 16): | ||
print("Longitud no válida. Debe estar entre 8 y 16 caracteres.") | ||
return | ||
|
||
mayus = input("Incluir letras mayúsculas (si/no): ").lower() == 'si' | ||
numeros = input("Incluir números (si/no): ").lower() == 'si' | ||
simbol = input("Incluir símbolos (si/no): ").lower() == 'si' | ||
|
||
contrasena = contra(longitudContra, mayus, numeros, simbol) | ||
print(f"\nContraseña generada: {contrasena}") | ||
|
||
if __name__ == "__main__": | ||
main() |