code: def check_password_expired(user):
      
      if not settings.ACCOUNT_PASSWORD_USE_HISTORY:
          return False
  
      if hasattr(user, "password_expiry"):
          # user-specific value
          expiry = user.password_expiry.expiry
      else:
          # use global value
          expiry = settings.ACCOUNT_PASSWORD_EXPIRY
  
      if expiry == 0:  # zero indicates no expiration
          return False
  
      try:
          # get latest password info
          latest = user.password_history.latest("timestamp")
      except PasswordHistory.DoesNotExist:
          return False
  
      now = datetime.datetime.now(tz=pytz.UTC)
      expiration = latest.timestamp + datetime.timedelta(seconds=expiry)
  
      if expiration < now:
          return True
      else:
          return False
docs: Return True if password is expired and system is using
      password expiration, False otherwise.