Generate A Django Secret Key

A Django application with a command to generate a Django secret key - 1.0.2 - a Python package on PyPI - Libraries.io. Generate a 50-char random string, adequate for Django's `SECRETKEY` - generatedjangosecretkey.py. Skip to content. All gists Back to GitHub. Sign in Sign up. Django Secret Key Generator Generate a new key. Django Secret Key Generator Generate a new key.

Feb 16, 2020  With this Freemake Video Downloader Serial Key 3.8.4.49 generator program you can specify the desired download location as well. It allows you to works all these features with the very small amount of system. It more than a simple downloader it offers many other features not. Freemake video downloader premium pack serial key generator. Apr 16, 2020  Freemake Video Converter 4.1.11.0 Crack 2020 Full Download is a freemium video and movie converting software. It helps you to convert your videos in more than 600+ non-prohibited formats. Also, it is one of the best non-linear video converting tools. Jan 16, 2020  Moreover, it allows you to rip web links directly to MKV, AVI, PSP, iPhone, WMV, Android, and Amazon Kindle etc. Freemake Video Downloader Premium Pack Key allows the user to save more than one video simultaneously. The user can create a downloading queue as well. Further, it allows the user to save any type of YouTube content for offline use.

  1. Generate Django Secret Key
  2. Generate A Django Secret Key Generator

Generate Django Secret Key

Generate A Django Secret Key

Generate A Django Secret Key Generator

Generate a 50-char random string, adequate for Django's `SECRET_KEY`
generate_django_secret_key.py
#!/usr/bin/env python
# coding: utf-8
''Generate a 50-char random string, adequate for Django's ``SECRET_KEY``.
source: part of
https://github.com/django/django/blob/1.8.5/django/utils/crypto.py
''
from __future__ importabsolute_import, print_function, unicode_literals
importhashlib
importrandom
importtime
try:
random=random.SystemRandom()
using_sysrandom=True
exceptNotImplementedError:
importwarnings
warnings.warn('A secure pseudo-random number generator is not available '
'on your system. Falling back to Mersenne Twister.')
using_sysrandom=False
defget_random_string(length=12,
allowed_chars='abcdefghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'):
''
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
''
ifnotusing_sysrandom:
# This is ugly, and a hack, but it makes things better than
# the alternative of predictability. This re-seeds the PRNG
# using a value that is hard for an attacker to predict, every
# time a random string is required. This may change the
# properties of the chosen random sequence slightly, but this
# is better than absolute predictability.
random.seed(
hashlib.sha256(
('%s%s%s'% (
random.getstate(),
time.time(),
# settings.SECRET_KEY,
',
)).encode('utf-8')
).digest())
return'.join(random.choice(allowed_chars) foriinrange(length))
defmain():
# chars and length as defined in Django command 'startproject'
# https://github.com/django/django/blob/1.8.5/django/core/management/commands/startproject.py#L30
chars='abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
returnget_random_string(50, chars)
if__name__'__main__':
print(main())
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
commandline.txt
$ python -c 'import random; print '.join([random.choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])'

commented Aug 22, 2018

For Python 3, this should work:

python -c 'import random; result = '.join([random.choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]); print(result)'

commented Jun 2, 2019

commented Jun 3, 2019

For Python 3, this should work:

python -c 'import random; result = '.join([random.choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]); print(result)'

I think you should use parenthesis while using print method in Python 3
python -c 'import random; print('.join([random.choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]))'

commented Oct 13, 2019

Seems exceedingly unlikely the random package contains a sufficiently secure random.

In Linux you can read from /dev/urandom or /dev/random(slower) and see someone suggesting random.SystemRandom which is probably more portable.

commented Feb 27, 2020
edited

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment