[mod_python] populate user name in login prompt (for session)

Chris Jackson christopher.jackson at gmail.com
Wed Jan 19 13:43:05 EST 2005


You could just use Apache Authentication.  They have an automatic
login popup, and then your PythonAuthenHandler can pick up the
username and password that was entered.

~= Chris =~


On Wed, 19 Jan 2005 10:20:25 -0800 (PST), Robert Thomas Davis
<rdavisunr at yahoo.com> wrote:
> Hey all
> 
> My site requires a password to be accessed...I do not
> really care what the user name is.  Thus, I would like
> to populate the login prompt with a default name, like
> user or admin, etc.  Is this possible or is it
> possible to just prompt for a password and nothing
> else?  I have included the code I am using (this code
> was clipped from an earlier post and modified).
> 
> Thanks
> 
> Rob
> 
> def __auth__(req, user, passwd):
> 
>      # removed check for user=USER
> 
>      if passwd == PASS:
>              # user has successfully authenticated
>              sess = Session(req)
> 
>              if sess.has_key('max_inactive'):
>                      # this is an existing session
> 
>                      # check length of inactivity
>                      elapsed = time.time() -
> sess['last']
> 
>                      # reset timer for next request
>                      sess['last'] = time.time()
>                      sess.save()
> 
>                      # compare elapsed inactivity to
> maximum allowed
>                      if elapsed >
> sess['max_inactive']:
>                              # it's been too long
> 
>                              # uncomment to delete
> session (optional)
>                              sess.delete()
> 
>                              # force user to
> reauthenticate
>                              return 0
>                      else:
>                              # still within time limit
>                              #
> req.write("Authorized.\n\n")
> 
>                              # allow user to continue
>                              return 1
>              else:
>                      # this must be a new session, so
> set session variables
> 
>                      # set maximum inactivity allowed,
> in seconds
>                      sess['max_inactive'] = 500
> 
>                      # initialize timer
>                      sess['last'] = time.time()
> 
>                      sess.save()
> 
>                      # do new session stuff here
>                      # req.write("Session
> started.\n\n")
> 
>                      # allow user to continue
>                      return 1
>      else:
>              # wrong user or password, force user to
> reauthenticate
>              return 0
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list