3 ms·
The code is overcomplicated and somewhat rough for what it does. Python docs has 4 line snippet that you just copypaste if you need: import secrets # O
by zokier 2y ago
The code is overcomplicated and somewhat rough for what it does. Python docs has 4 line snippet that you just copypaste if you need:
import secrets
# On standard Linux systems, use a convenient dictionary file.
# Other platforms may need to provide their own word-list.
with open('/usr/share/dict/words') as f:
words = [word.strip() for word in f]
password = ' '.join(secrets.choice(words) for i in range(4))
https://docs.python.org/3/library/secrets.html#recipes-and-best-practices https://docs.python.org/3/library/secrets.html#recipes-and-b...
Also EFF had prepared convenient wordlists specifically for password generation: https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases https://www.eff.org/deeplinks/2016/07/new-wordlists-random-p...
- Cthulhu_ 2y agoI love how several comments have turned this into code golf :D. There's another comment that shows a shell oneliner using the word dictionary.
- zenethian 2y agoYeah, the code looks like it was written by a Java programmer writing Python code.
- homebrewer 2y agoFor truly paranoid, 1password has an 18328-word password list: https://raw.githubusercontent.com/agilebits/crackme/refs/heads/master/doc/AgileWords.txt https://raw.githubusercontent.com/agilebits/crackme/refs/hea... which is what their own generator uses, I think. If you're using four words, it gives you (18328⁴ / 7776⁴ ≈ 30.86) times larger space over EFF's list.