Commit 9ff57fa8 authored by Jérome Perrin's avatar Jérome Perrin

PasswordTool: use python's uuid module to generate random unique id

parent 8d90b547
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
import socket import socket
import uuid
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass, DTMLFile, get_request from Products.ERP5Type.Globals import InitializeClass, DTMLFile, get_request
...@@ -80,7 +81,7 @@ class PasswordTool(BaseTool): ...@@ -80,7 +81,7 @@ class PasswordTool(BaseTool):
expiration_date = DateTime() + self._expiration_day expiration_date = DateTime() + self._expiration_day
# generate a random string # generate a random string
key = self._generateUUID() key = uuid.uuid4().hex
if isinstance(self._password_request_dict, PersistentMapping): if isinstance(self._password_request_dict, PersistentMapping):
LOG('ERP5.PasswordTool', INFO, 'Migrating password_request_dict to' LOG('ERP5.PasswordTool', INFO, 'Migrating password_request_dict to'
' OOBTree') ' OOBTree')
...@@ -217,24 +218,6 @@ class PasswordTool(BaseTool): ...@@ -217,24 +218,6 @@ class PasswordTool(BaseTool):
return redirect(REQUEST, site_url, return redirect(REQUEST, site_url,
translateString("An email has been sent to you.")) translateString("An email has been sent to you."))
def _generateUUID(self, args=""):
"""
Generate a unique id that will be used as url for password
"""
# this code is based on
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/213761
# by Carl Free Jr
# as uuid module is only available in pyhton 2.5
t = long( time.time() * 1000 )
r = long( random.random()*100000000000000000L )
try:
a = socket.gethostbyname( socket.gethostname() )
except:
# if we can't get a network address, just imagine one
a = random.random()*100000000000000000L
data = ' '.join((str(t), str(r), str(a), str(args)))
return md5(data).hexdigest()
security.declareProtected(Permissions.ModifyPortalContent, 'removeExpiredRequests') security.declareProtected(Permissions.ModifyPortalContent, 'removeExpiredRequests')
def removeExpiredRequests(self): def removeExpiredRequests(self):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment