1- # $Id: client.py,v 1.171 2004-04-20 21:57:10 richard Exp $
1+ # $Id: client.py,v 1.172 2004-04-22 22:16:36 richard Exp $
22
33"""WWW request handler (also used in the stand-alone server).
44"""
77import os , os .path , cgi , StringIO , urlparse , re , traceback , mimetypes , urllib
88import binascii , Cookie , time , random , stat , rfc822
99
10+
1011from roundup import roundupdb , date , hyperdb , password
1112from roundup .i18n import _
1213from roundup .cgi import templating , cgitb
@@ -97,6 +98,8 @@ class Client:
9798 # pagesize, startwith
9899
99100 def __init__ (self , instance , request , env , form = None ):
101+ # re-seed the random number generator
102+ random .seed ()
100103 if __debug__ :
101104 hyperdb .traceMark ()
102105 self .start = time .time ()
@@ -612,8 +615,15 @@ def set_cookie(self, user):
612615
613616 Also store away the user's login info against the session.
614617 """
615- # TODO generate a much, much stronger session key ;)
616- self .session = binascii .b2a_base64 (repr (random .random ())).strip ()
618+ sessions = self .db .getSessionManager ()
619+
620+ # generate a session key
621+ s = '%s%s' % (time .time (), random .random ())
622+ print s
623+ self .session = binascii .b2a_base64 (s ).strip ()
624+ while sessions .exists (self .session ):
625+ s = '%s%s' % (time .time (), random .random ())
626+ self .session = binascii .b2a_base64 (s ).strip ()
617627
618628 # clean up the base64
619629 if self .session [- 1 ] == '=' :
@@ -623,7 +633,6 @@ def set_cookie(self, user):
623633 self .session = self .session [:- 1 ]
624634
625635 # insert the session in the sessiondb
626- sessions = self .db .getSessionManager ()
627636 sessions .set (self .session , user = user )
628637 self .db .commit ()
629638
0 commit comments