Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6053867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:05:19+00:00 2026-05-23T08:05:19+00:00

We use custom authentication for our django webapp, where we hit the company ldap.

  • 0

We use custom authentication for our django webapp, where we hit the company ldap. Since we’re using a custom backend, we seem to only be able to return None, or the username of a user from our db.

def authenticate(self,username,password):
    """
    Authenticate the username credentials, and return the 
    """
    try:
        self.ldap.simple_bind_s(username+"@"+settings.AUTH_LDAP_DOMAIN,password)
        self.ldap.unbind_s()

    except ldap.INVALID_CREDENTIALS:
        logger.debug("Invalid credentials used for login.")
        username = None
    except ldap.SERVER_DOWN, e:  
        logger.debug("Ldap server is down.")
        username = None

    return username

Clearly there are three different use cases here – one where it works, one where it doesn’t because the credentials are invalid, and one where the server is down. Django’s custom backend seems to only really handle two of these though – invalid credentials, or working ones. How would I redirect to an error page, or inform the user that ldap is down?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:05:20+00:00Added an answer on May 23, 2026 at 8:05 am

    I’d look at raising a custom exception in your auth backend, and catch it in your login view. Returning None from your auth backend simply means “I couldn’t authenticate these credentials – try the next backend”.

    So, in pseudo-code,

    class LoginView(TemplateView):
        def post(self, request):
            try:
                user = authenticate(request.POST['username'], request.POST['password'])
            except MyCustomLdapError:
                return HttpResponseRedirect('ldap_server_unavailable.html')
            else:
                if user:
                    return HttpResponseRedirect('logged_in.html')
                else:
                    return HttpResponseRedirect('login_failed.html')
    

    In real life, you’d of course use a form to validate some of this – but you get the idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a custom authentication backend for Django (which runs off couchdb). I
We use custom type to represent Identifiers in our project. It has TypeConvertor attached
I want to use custom exception handling, for example instead of using (Exception ex)
I am using wordpress and use custom permalink structure: /%category%/%postname%/ My problem is that
I am working on two ASP.NET websites. Both use custom authentication process based on
All our inhouse projects use Active Directory authentication and impersonation as this is the
I'm trying to use a custom JAAS authentication module for a web based application
Our system uses a custom roles, and authentication system to Authenticate users. I am
I use Spring Security 3.0.3.RELEASE. I would like to create a custom authentication processing
I'm trying to have my custom java application use our Active Directory Server for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.