Home > Enterprise >  Entering wrong username and password still django authenticate it as correct
Entering wrong username and password still django authenticate it as correct

Time:01-30

I am trying to create a login page in Django when the login details are filled in correctly it redirect to a certain page the problem I am facing is that when I enter wrong username or password Django authenticate them as correct and redirect it to another page my login code is as follows

def loginpage(request):
    if request.method=='POST':
        use=request.POST.get('username')
        pas=request.POST.get('password')
        
        
        user=authenticate(request,username=use,password=pas)
        if user is not NONE:
            login(request,user)
            return redirect('data')
            
        else:
            messages.info(request,'Username or Password is incorrect')
            return render(request,'login.html')
          
    ```
even after entering the username that doesn't even exist in the database Django authenticate as right and doesn't show the error that I am expecting 

CodePudding user response:

You have uppercase NONE instead of None. You must have accidentally imported NONE from pickle or some other library, and that's why it's validating instead of raising an error. Check your imports at the top of the file and change to if user is not None.

CodePudding user response:

Can you clarify a bit. It needs a better explanation. For example, what does authenticate method do? (Couldn't comment due to reputation limitations)

  •  Tags:  
  • Related