Login page is verifying all users as good Django

162
January 21, 2021, at 03:00 AM

I'm trying to build a login page in Django. But whenever I try to authenticate the user it doesn't work. The user passes each time even if the user doesn't exist. Any help I would really appreciate it!

def login(request):
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
    form = CreateUserForm()
    return render(request,
                  "leadfinderapp/login.html",
                  context={"form":form})
Answer 1

The user isn't actually getting authenticated, you just aren't handling errors in the form. The function is just rendering the "leadfinderapp/login.html" template again regardless of the user's data entered.

To handle errors in the form, you need to have a

if form.is_valid():
    # submit information and login
else:
    # re render form with errors

You should look into using Django All Auth to handle your authentication (https://django-allauth.readthedocs.io/en/latest/installation.html) it's customizable but handles a lot of the work for you - just like Django itself!

READ ALSO
how to calculate employee attendace data

how to calculate employee attendace data

this is the employee_attendance table in mysql in which i have 3 column id, emp_id and office_punchoffice_punch is employee in time or out time with date

94
Start Application class A from different Application class B in same Android bundle

Start Application class A from different Application class B in same Android bundle

I have Application class A in base module and i want to launch other Application Class B in dynamic feature module

87
Node Schedule with mongoDB

Node Schedule with mongoDB

I want to use Node Schedule to build a module that will backup my serversI have the configuration of the backup periodicity in a MongoDB

88
Snake AI collide with himself when it shouldn't

Snake AI collide with himself when it shouldn't

I've started to make a snake ai game

60