mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-26 03:24:01 +03:00
An small pythonic approach to password (#1036)
* 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. * Adding missing line Adding missing import at the head of the file. The previous commit added the string content, but I didn't added the needed import line. This fixes it.
This commit is contained in:
parent
f4ef73efbf
commit
44f67452a9
|
@ -16,6 +16,7 @@ from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
|
import string
|
||||||
|
|
||||||
# Get the root project directory
|
# Get the root project directory
|
||||||
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
|
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
|
||||||
|
@ -28,16 +29,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