Skip to content

Instantly share code, notes, and snippets.

@birkin
Last active July 3, 2017 17:00
Show Gist options
  • Save birkin/0f6245dd7eeb24c0f5ad to your computer and use it in GitHub Desktop.
Save birkin/0f6245dd7eeb24c0f5ad to your computer and use it in GitHub Desktop.
generates key (like django secret-key) string with no possibly-mistaken characters
# -*- coding: utf-8 -*-
import random
random = random.SystemRandom()
ALLOWED_CHARACTERS = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789' # evil oft-mistaken chars left out
LENGTH = 50 # django
secret_key = ''.join( random.choice(ALLOWED_CHARACTERS) for i in range(LENGTH) )
print( secret_key ) # outputs, eg, 'PFxkGZSutc82psTD2hyrAxnaFRRu9sArVGqyJTW85kGnZWYsyb'
@birkin
Copy link
Author

birkin commented Aug 17, 2015

credit: from pythonadventures post

other good info: comment by franlu at geoffalday gist

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