Advertisement
JPablos

Generador Clave. Simple. Python

May 26th, 2022
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # -*- coding: utf-8 -*-
  4.  
  5. """
  6.     Generador Simple de clave
  7.    Clave generada con 12
  8.    carácteres alfanuméricos
  9.    --> Cambiar range(12) para mayor
  10.         o menor extensión de la clave
  11.        
  12.        Salida con range(12) -->  `As1xeZ8Nk6M0`
  13.        Salida con range(10) -->  `V24woaEX4U`
  14. """
  15.  
  16.  
  17. import string
  18. import secrets
  19.  
  20. alfabeto = string.ascii_letters + string.digits
  21.  
  22. while True:
  23.     password = ''.join(secrets.choice(alfabeto) for i in range(12))
  24.     if (any(c.islower() for c in password)
  25.             and any(c.isupper() for c in password)
  26.             and sum(c.isdigit() for c in password) >= 3):
  27.         break
  28.  
  29. print(password)
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement