recentpopularlog in

Copy this bookmark:





to read

bookmark detail

15.7. secrets — Generate secure random numbers for managing secrets — Python 3.6.0b4 documentation
Generate a ten-character alphanumeric password with at least one lowercase character, at least one uppercase character, and at least three digits:

import string
alphabet = string.ascii_letters + string.digits
while True:
password = ''.join(choice(alphabet) for i in range(10))
if (any(c.islower() for c in password)
and any(c.isupper() for c in password)
and sum(c.isdigit() for c in password) >= 3):
break

Generate an XKCD-style passphrase:

# 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(choice(words) for i in range(4))
python  passwords  security  solution 
november 2016 by kme
view in context