Skip to content

Instantly share code, notes, and snippets.

@mark-mishyn
Created March 8, 2019 17:31
Show Gist options
  • Save mark-mishyn/e6e7d9391c29431bd0838059d3f60f4f to your computer and use it in GitHub Desktop.
Save mark-mishyn/e6e7d9391c29431bd0838059d3f60f4f to your computer and use it in GitHub Desktop.
generate strong password in Django
import string
from django.utils.crypto import get_random_string
def generate_strong_password(length=12):
allowed_chars = string.digits + string.ascii_letters + '+=~|*_-#'
while True:
password = get_random_string(length=length, allowed_chars=allowed_chars)
if (set(password) & set(string.ascii_lowercase) and
set(password) & set(string.ascii_uppercase) and
set(password) & set(string.digits) and
set(password) & set(string.punctuation)):
return password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment