doubleo
doubleo

Reputation: 4759

django-passwords is not working

I am trying to use the django app - https://github.com/dstufft/django-passwords, to set up password strength checking for django passwords. Here are things i have done till now:

  1. Installed django-passwords with

    pip install django-passwords
    
  2. Added 'passwords' to INSTALLED_APPS
  3. Created a form:

    from passwords.fields import PasswordField
    class ResetForm(forms.Form):
      password = PasswordField(label="New password")
      confirmPassword = PasswordField(label="Confirm new password")
    
  4. Added the form in my page
  5. In settings.py added the field

    PASSWORD_MIN_LENGTH = 6
    
  6. Form shows up fine in the page. When i enter a password which is less than 6 characters, no error appears.

Is there a anything i am missing or anything i should do to get it to work ?

Any help will be really appreciated.

Upvotes: 0

Views: 88

Answers (1)

Wouter Klein Heerenbrink
Wouter Klein Heerenbrink

Reputation: 1391

If your code is literarily as you typed in your comment, then the issue is with your code definition. From what you write, your view definition is:

def index(request):
    return render_to_response('templateName', {'form': ResetForm})

You never instantiate the form and you new add the POST-data to the form. Change it to:

def index(request):
    if request.method == 'POST':
        form = ResetForm(data=request.POST)
    else:
        form = ResetForm()

    return render_to_response('templateName', {'form': form})

This should work :-).

Perhaps your better off using the render method for this includes a RequestContext object that handles the CSRF token.

More info on this subject: https://docs.djangoproject.com/en/1.8/topics/forms/#the-view

Upvotes: 1

Related Questions