Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django 1.9 createsuperuser bypass the password validation checking

Try to work on the new django 1.9 version, and create a super user by this:

python manage.py createsuperuser

And I just want to use a simple password for my local development environment, like only one character, django1.9 upgrade to a very strict password validation policy, how can I bypass it?

Password: 
Password (again): 

This password is too short. It must contain at least 8 characters.

This password is too common.

This password is entirely numeric.
like image 333
Liao Zhuodi Avatar asked Feb 11 '16 03:02

Liao Zhuodi


People also ask

How does Django validate email and password?

validate(self, password, user=None) : validate a password. Return None if the password is valid, or raise a ValidationError with an error message if the password is not valid. You must be able to deal with user being None - if that means your validator can't run, return None for no error.


2 Answers

After creating the superuser with a complex password, you can set it to something easier in the shell (./manage.py shell):

from django.contrib.auth.models import User
user = User.objects.get(username='your_user')
user.set_password('simple')
user.save()
like image 102
mimo Avatar answered Sep 20 '22 06:09

mimo


In fact, you do not need to modify the validator settings or first create a complex password and then later change it. Instead you can create a simple password directly bypassing all password validators.

Open the django shell

python manage.py shell

Type:

from django.contrib.auth.models import User

Hit enter and then type (e.g. to use a password consisting only of the letter 'a'):

User.objects.create_superuser('someusername', '[email protected]', 'a')

Hit enter again and you're done.

like image 30
User Avatar answered Sep 20 '22 06:09

User