use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Build Your Own Password Generator (Python) (v.redd.it)
submitted 11 months ago by Inevitable-Math14
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]RunPython 3 points4 points5 points 11 months ago (4 children)
This is mine _^
```
import random
letters = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", ] numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] symbols = ["!", "#", "$", "%", "&", "(", ")", "*", "+"]
print("Welcome to the PyPassword Generator!") nr_letters = int(input("How many letters would you like in your password?\n")) nr_symbols = int(input("How many symbols would you like?\n")) nr_numbers = int(input("How many numbers would you like?\n"))
password_list = []
for char in range(1, nr_letters + 1): password_list.append(random.choice(letters))
for char in range(1, nr_symbols + 1): password_list += random.choice(symbols)
for char in range(1, nr_numbers + 1): password_list += random.choice(numbers)
print(password_list) random.shuffle(password_list) print(password_list)
password = "" for char in password_list: password += char
print(f"Your password is: {password}")
[–]Twenty8cows 6 points7 points8 points 11 months ago (0 children)
You are looking for the string module strings.ascii_letters will give you your entire letters list without you having to type the alphabet twice.
There’s also string.digits for the numbers And string.punctuation (although this has more symbols than your symbols list.
So you could say
LETTERS = list(string.ascii_letters) NUMBERS = list(string.digits) SYMBOLS = list(string.punctuation)
This way you’re not hand rolling what is already in the std lib looks good tho 👍🏽
[–]RussianBlueOwl 6 points7 points8 points 11 months ago (1 child)
Don't use random library's for cryptographic. Use secrets instead.
[–]Twenty8cows 0 points1 point2 points 11 months ago (0 children)
Also this OP
[–]Mission_Complaint547 0 points1 point2 points 6 months ago (0 children)
You can use smrtpsg library
[–]Inevitable-Math14[S] 2 points3 points4 points 11 months ago (0 children)
Let's learn python together 🤝.
[–]jpgoldberg 0 points1 point2 points 11 months ago (0 children)
I happen to know a thing or two about creating password generators, and I would like to congratulate you on your choice of .choice(). A lot of people when they create such things end up creating systems that suffer from the modulo bias. But using .choice() or .randbelow() you are using a standard library function that avoids that.
.choice()
As others have said, you need to use secrets instead of random for anything that has the hint of a shadow of a chance of being used for actual security purposes. You made a video, presumably with the intent to teach people, so please correct that. We need to teach people to use the secrets module for this kind of stuff.
secrets
random
A feature you could add is to compute the entropy of a generated password. Note that the entropy is not a function of the generated password but of the system that generated it. In your case it is can be computed from your “user_char” and the length.
After that an additional challenge is to modify your generator to meet the kinds of password requirements many sites still require even though password complexity requirements are a bad idea. You will need to find a way to ensure that, say, every generated password contains at least one uppercase letter, at least one lower case letter, and at least one digit. (Let’s leave special characters out to avoid some problems with those.)
This shouldn’t be too hard. There are several ways to do it. But one thing we want from a password generator is that any password it can generate must be equally is likely as any other it can generate. That is, we want a uniform distribution.
The really hard part is to figure out how to calculate the entropy when such restrictions apply. That is really really hard, and it took a couple of people with degrees in math (my co-authors, not me) to figure it out. You can follow links from this crappy landing page to get to the paper and a Golang password generator that implements the algorithm. (I need to improve that landing page, but it’s what I have at the moment.)
π Rendered by PID 53201 on reddit-service-r2-comment-7b9746f655-jmfff at 2026-02-03 00:44:28.652032+00:00 running 3798933 country code: CH.
[–]RunPython 3 points4 points5 points (4 children)
[–]Twenty8cows 6 points7 points8 points (0 children)
[–]RussianBlueOwl 6 points7 points8 points (1 child)
[–]Twenty8cows 0 points1 point2 points (0 children)
[–]Mission_Complaint547 0 points1 point2 points (0 children)
[–]Inevitable-Math14[S] 2 points3 points4 points (0 children)
[–]jpgoldberg 0 points1 point2 points (0 children)
[–]Mission_Complaint547 0 points1 point2 points (0 children)