tags:

views:

73

answers:

2

I am trying to get a login form I have in django to only allow three login attempts before redirecting to a "login help" page. I am currently using the builtin "django.contrib.auth.views.login" view with a custom template. How do I force it to redirect to another page after n failed login attempts?

A: 

You could save a session if the user has failed to login.

request.SESSION['login_tries'] = 1

and if they fail to login again

request.SESSioN['login_tries'] = 2

If the session becomes equal to the amount of login tries you want them tho have, then do something.

dotty
+1  A: 

There's actually a project out there which provides a Django middleware to do just this, called django-axes. Simply install it with the instructions provided and then set AXES_LOGIN_FAILURE_LIMIT to the number of login attempts you want before a record is created for the failed logins. You'll still have to check this record when you want to lock someone out, however.

Daniel DiPaolo
Thanks Daniel. I chose dotty's answer because it was closer to the method I ended up using. Part of the issue was my own inexperience with Python and Django and as such I didn't have enough knowledge to ask the right question. I think your answer would have been just as good if not better if I wanted something with that many features, and I may well end upo using it when I am more familiar with the framework.
RED MONKEY
No worries, just wanted to let you know that there was a solution out there already that could potentially work. I didn't know it existed either so I learned something in the process too!
Daniel DiPaolo