Dolda2000 GitWeb
/
wrw.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8207156
)
Make session.gennonce more sound.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Thu, 3 Apr 2014 04:02:40 +0000
(06:02 +0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Thu, 3 Apr 2014 04:02:40 +0000
(06:02 +0200)
wrw/session.py
patch
|
blob
|
blame
|
history
diff --git
a/wrw/session.py
b/wrw/session.py
index
1e615e3
..
0c585a3
100644
(file)
--- a/
wrw/session.py
+++ b/
wrw/session.py
@@
-3,21
+3,12
@@
import cookie, env
__all__ = ["db", "get"]
__all__ = ["db", "get"]
-def hexencode(str):
- ret = ""
- for byte in str:
- ret += "%02X" % (ord(byte),)
- return ret
-
def gennonce(length):
def gennonce(length):
- nonce = ""
- for i in xrange(length):
- nonce += chr(random.randint(0, 255))
- return nonce
+ return os.urandom(length)
class session(object):
def __init__(self, lock, expire=86400 * 7):
class session(object):
def __init__(self, lock, expire=86400 * 7):
- self.id =
hexencode(gennonce(16)
)
+ self.id =
gennonce(16).encode("hex"
)
self.dict = {}
self.lock = lock
self.ctime = self.atime = self.mtime = int(time.time())
self.dict = {}
self.lock = lock
self.ctime = self.atime = self.mtime = int(time.time())