From a3ef63da396a1a89e2a75cf9f51a6467e13ad3bc Mon Sep 17 00:00:00 2001 From: Sebastian Reyes Espinosa Date: Mon, 13 Feb 2017 15:29:55 -0500 Subject: [PATCH] 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. --- hooks/post_gen_project.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 068d74831..8cc2a3f90 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -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"