r/PythonLearning • u/shubham_555 • 2d ago
Showcase I made a simple Password Generator! 👀
Last Post- https://www.reddit.com/r/PythonLearning/s/dZhrMNIx9T
Github Repo Link - https://github.com/Dev-4-All/password-generator.git
25
Upvotes
3
u/dev-razorblade23 2d ago
For producing cryptographically safe random results, you should use secrets module (https://docs.python.org/3/library/secrets.html) instead of random as this is more meant for games and non-security related stuff.
3
1
u/DrlNoV 1d ago edited 1d ago
import random , string
alphabets = list(string.ascii_letters)
numbers_10 = list(str(i) for i in range(10)) or list(string.digits)
symbols = list(string.punctuation)
for password you can simply += the choices to it
here is the full code of one that i made.
import random , string
alphabets = list(string.ascii_letters)
numbers_10 = list(str(i) for i in range(10))
symbols = list(string.punctuation)
#Each individual character in things has an equal probability of being selected.
things = alphabets + numbers_10 + symbols
#Checks the password so it cannot be negative or letters
while True:
lenght = (input("Lenght :").strip())
try:
lenght = int(lenght)
if lenght >= 0:
break
else:
print("No negative!")
except:
print("numbers only")
password = ""
while True:
if len(password) == lenght:
break
choice = random.choice(things)
password += (choice)
print(password)
1
•
u/Sea-Ad7805 1d ago
Run this program in Memory Graph Web Debugger to see the program state change step by step.