An small pythonic approach to password

Providing a more pythonic line for password generation using for that the string content, as suggested for the documentation in #949.
This commit is contained in:
Sebastian Reyes Espinosa 2017-02-13 15:29:55 -05:00 committed by GitHub
parent f4ef73efbf
commit a3ef63da39

View File

@ -28,16 +28,17 @@ except NotImplementedError:
using_sysrandom = False
def get_random_string(
length=50,
allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789!@#%^&*(-_=+)'):
def get_random_string(length=50):
"""
Returns a securely generated random string.
The default length of 12 with the a-z, A-Z, 0-9 character set returns
a 71-bit value. log_2((26+26+10)^12) =~ 71 bits
"""
if using_sysrandom:
return ''.join(random.choice(allowed_chars) for i in range(length))
return ''.join(random.choice(
string.digits + string.ascii_letters + string.punctuation
) for i in range(length))
print(
"Cookiecutter Django couldn't find a secure pseudo-random number generator on your system."
" Please change change your SECRET_KEY variables in conf/settings/local.py and env.example"