Search code examples
pythondjangodjango-viewsdjango-authentication

Multiple Password DJANGO


I am creating an app that authenticates with users for AD, but then it also needs separate passwords to authenticate for two other services. Is there a way to use 3 passwords to verify login? I can set up log in verification individually for each service, but I was wondering if I could store all three passwords in the same session. Reason being is because users will need to authenticate with multiple services to use all functions of this app.

here is roughly what I am doing in my view.py

        request.session['pass_kinit2030'] = password
        request.session['reg_pass'] = reg_pass
        request.session['oraclepass'] = oraclepass


Solution

  • I ended up using multiple try/except methods to testing the logging in on the other other services. try:

       try:
            a = add_user().login(username=creds['user'], password=creds['banpass'])
            add_user().logout(a)
        except:
            messages.error(request, 'Banner Password Is Incorrect')
            return redirect('login')
        if Usermanager(creds=creds).test_login():
            pass
        else:
            messages.error(request, 'Wrong Regular Account Credentials')
            return redirect('login')
        if user is not None:
            auth.login(request, user)
            return redirect('userinfo')
        else:
            messages.error(request, 'Wrong AdminCredentials')
            return redirect('login')