title: DJango: authenticate function vs verifying username, password and is_active
body: <p>I am working on a Django Project:</p>
  
  <p>I have a login form with username and password</p>
  
  <p>Generally i observed authenticate function is used to authenticate a user and pass i.e</p>
  
  <pre><code>user = authenticate(username, password)
  </code></pre>
  
  <p>I tried to understand the authenticate function but i found it is not so easy.</p>
  
  <p>Instead of using the authenticate function i want to check the authentication the following way:</p>
  
  <p>1) check if the username exists</p>
  
  <p>2) check if the password matches</p>
  
  <p>3) check if is_active is true.</p>
  
  <p>Which i can do by the following way:</p>
  
  <pre><code>username = self.cleaned_data.get('username')
  password = self.cleaned_data.get('password')
  
  # check if user exists
  try:
      user = User.objects.get(username=username)
  except User.DoesNotExist:
      user = None
  
  #check if user is_active
  if user.is_active:
      user_active = true
  else
      user_active = false
  
  #check the password
  
  if user_active:
      password_match = user.check_password(password):
  else:
      password_match = false
  
  if password_match:
      msg = "Login Successful"
  else:
      msg = "Login Failed"
  </code></pre>
  
  <p>Will the above serve the same purpose as authenticate function or is there something else to be checked.</p>