r/PythonLearning 2d ago

Showcase I made a simple Password Generator! 👀

Post image
25 Upvotes

6 comments sorted by

u/Sea-Ad7805 1d ago

Run this program in Memory Graph Web Debugger to see the program state change step by step.

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

u/Routine_Ant4297 1d ago

👍 good job 👍

2

u/mr-fba 1d ago

Good, but 1. Hardcoded the string, digits and symbols, instead of using string lib.

2.why you added letters in an array and not added as a simple string then access by its index!?

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/riklaunim 2d ago

Check Python string module (string.ascii_letters, string.digits and alike).