[Tutor] Python and NT Authentication
Chris Fuller
cfuller084 at thinkingplanet.net
Thu Aug 7 19:08:24 CEST 2008
You should search/browse MSDN for authentication info. Also, you can run
Apache on windows, if that eases your migration.
http://msdn.microsoft.com/en-us/library/aa374735(VS.85).aspx
This probably what you want. Just be sure to keep your authentication code as
modular as possible, if you are planning to dump a few apple carts as it
sounds like you might.
I don't know how big a deal it would be to maintain two separate
authentication systems, but you might want to consider some other way than
going through the win32 api. There might be some way you could use LDAP or
such, to ease administration. Stick to open standards and protocols when
possible :) Notwithstanding how messy the win32 api is, of course :)
Cheers
On Thursday 07 August 2008 09:55, Steven L Smith wrote:
> Hello, everyone-
>
> I'm trying to both learn Python and develop a fairly robust web form with
> it at the same time... nothing like being thrown into a new job and having
> to learn a new language to do it!
>
> We have ActiveState Python 2.5 installed on an IIS box running Windows
> 2003. We're doing it this way because we will most likely be switching to
> Apache / Unix in the future, and we don't want to have to rewrite all of
> our server-side scripts. Our web server is a domain member.
>
> I am coding a form that will allow authenticated NT users to submit project
> requests. The form will, among other things, need to pull a list of domain
> users and put it into a dropdown menu, as well as show the username of the
> current user. Results will be dumped into an ODBC-connected mySQL database,
> which is working well (it's just the authentication issue that I'm
> struggling with).
>
> I am able to connect to the domain with the following:
>
> <%import ldap, sys, win32api
> LDAP_SERVER='ldap://nazareth.internal'
> LDAP_USERNAME='myusername at nazareth.internal'
> LDAP_PASSWORD='mypassword'
>
> try:
> ldap_client = ldap.initialize(LDAP_SERVER)
> ldap_client.simple_bind_s(LDAP_USERNAME, LDAP_PASSWORD)
>
> except ldap.INVALID_CREDENTIALS, e:
> Response.Write("<h1 style='color:red'>Invalid credentials</h1>")
> sys.exit()
> except ldap.SERVER_DOWN, e:
> Response.Write("<h1 style='color:red'>Your server appears to be
> down.</h1>") sys.exit()
>
> Response.Write("<h1 style='color:blue'>Connected! All is well.</h1>")
> ldap_client.unbind()
> %>
>
> However, other than hard-coding the variables, I don't know how to get them
> from the user, nor do I know how to actually authenticate them. Should I be
> using Cookies? How is that done?
>
> As far as populating the form's <select> dropdown box, I've been using
> something similar to:
>
> <%
> import pyodbc
> cnxn_ro = pyodbc.connect("DSN=metaproject_ro")
> cursor = cnxn_ro.cursor()
> cursor.execute("select * from Person order by last_name, first_name")
> for row in cursor:
> Response.Write("<option value='"+row.uid+"'>"+row.last_name+",
> "+row.first_name+" ("+row.uid+")</option>") cursor.close()
> %>
>
> (for testing purposes, I actually built a table in the database just so
> that I could populate it programmatically, but this is where I'd like to
> pull the info from Active Directory.
>
>
>
> Hope someone can help! I've been scouring the web for several hours, and
> I'm actually *more* confused than when I started.
>
>
> Thanks!
>
>
> Steven L Smith
> Web Developer
> Nazareth College of Rochester
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list