Created
March 8, 2019 17:31
-
-
Save mark-mishyn/e6e7d9391c29431bd0838059d3f60f4f to your computer and use it in GitHub Desktop.
generate strong password in Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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