from string import ascii_letters, digits, printable from account.models import User def auth_with_username_or_email(username, password): password = encode_password(password) if '@' in username: user = User.objects.get(email=username, password=password) else: user = User.objects.get(username=username, password=password) return user def check_password(password): if set(password).isdisjoint(ascii_letters) and set(password).isdisjoint(digits): return False return set(password).issubset(printable) and len(password) >= 8 def encode_password(password): import hashlib md5 = hashlib.md5() md5.update(password.encode()) return md5.hexdigest()