mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-04 20:20:18 +03:00
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:
parent
f4ef73efbf
commit
a3ef63da39
|
@ -28,16 +28,17 @@ except NotImplementedError:
|
||||||
using_sysrandom = False
|
using_sysrandom = False
|
||||||
|
|
||||||
|
|
||||||
def get_random_string(
|
def get_random_string(length=50):
|
||||||
length=50,
|
|
||||||
allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789!@#%^&*(-_=+)'):
|
|
||||||
"""
|
"""
|
||||||
Returns a securely generated random string.
|
Returns a securely generated random string.
|
||||||
The default length of 12 with the a-z, A-Z, 0-9 character set returns
|
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
|
a 71-bit value. log_2((26+26+10)^12) =~ 71 bits
|
||||||
"""
|
"""
|
||||||
if using_sysrandom:
|
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(
|
print(
|
||||||
"Cookiecutter Django couldn't find a secure pseudo-random number generator on your system."
|
"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"
|
" Please change change your SECRET_KEY variables in conf/settings/local.py and env.example"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user