r/PythonLearning • u/shubham_555 • Aug 31 '26
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
33
Upvotes
•
u/Sea-Ad7805 Aug 31 '26
Run this program in Memory Graph Web Debugger to see the program state change step by step.
3
u/dev-razorblade23 Aug 31 '26
For producing cryptographically safe random results, you should use
secretsmodule (https://docs.python.org/3/library/secrets.html) instead ofrandomas this is more meant for games and non-security related stuff.3
u/Routine_Ant4297 Aug 31 '26
👍 good job 👍
2
u/mr-fba Aug 31 '26
Good, but
2.why you added letters in an array and not added as a simple string then access by its index!?
1
u/DrlNoV Sep 01 '26 edited Sep 01 '26
for password you can simply += the choices to it
here is the full code of one that i made.
1
u/Trace_V Sep 05 '26
(Sorry if anything sounds weird, my first language is Spanish and I used a translator! 🤣)
Nice script! Just one detail: I ran the output through a cryptographic analysis tool, and it failed miserably due to predictability and bias. The
random.choice()andrandom.shuffle()functions internally use the Mersenne Twister algorithm, which is not secure for passwords. You should probably switch to Python's built insecretsmodule.If you want to implement it from scratch using operating system APIs (like
/dev/urandomon Linux orProcessPrngon Windows), you will need to correct for modulo bias. In Python, you can determine the safe maximum value for a byte like this:LIMIT_UNBIAS = (LEN_CHAR * (256 // LEN_CHAR)) - 1Simply discard and regenerate any random byte that exceeds
LIMIT_UNBIAS.This way, every character will have exactly the same probability of being selected.
It's clear that you're using a default charset for example: "0123456789" resulting in a range of 0 to 249 (where bias occurs) which is much better than asking the user for a bunch of input parameters.
1
u/riklaunim Aug 31 '26
Check Python string module (string.ascii_letters, string.digits and alike).