Skip to content

Instantly share code, notes, and snippets.

@mitshel
Created March 9, 2015 16:02
Show Gist options
  • Save mitshel/8aa63b8c2cc119949357 to your computer and use it in GitHub Desktop.
Save mitshel/8aa63b8c2cc119949357 to your computer and use it in GitHub Desktop.
SID Generation
#!/usr/bin/python
"""
Name: newSID.py
Author: Bill Anderson <bill@noreboots.com>
License: LGPL
This is a nice little means of generating a
"Session ID" for things like web sessions and the like.
It returns an ID of the format:
Joe_db2039967237b1b1be33222268408c1a
where "Joe" was the string passed to the function.
"""
import time,whrandom,md5
def getNewSID(tag):
"""Build a new Session ID"""
t1 = time.time()
time.sleep( whrandom.random() )
t2 = time.time()
base = md5.new( tag + str(t1 +t2) )
sid = tag + '_' + base.hexdigest()
return sid
if __name__ == '__main__':
print getNewSID('Joe')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment