fallback to old modules for centos5 (python 2.4)
authorBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Wed, 10 Feb 2010 16:23:46 +0000 (16:23 +0000)
committerBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Wed, 10 Feb 2010 16:23:46 +0000 (16:23 +0000)
PLC/Auth.py
PLC/Persons.py

index 945c8ce..08c9d2c 100644 (file)
@@ -9,7 +9,10 @@
 #
 
 import crypt
-import hashlib
+try:
+    from hashlib import sha1 as sha
+except ImportError:
+    import sha
 import hmac
 import time
 
@@ -257,7 +260,7 @@ class BootAuth(Auth):
             # We encode in UTF-8 before calculating the HMAC, which is
             # an 8-bit algorithm.
             # python 2.6 insists on receiving a 'str' as opposed to a 'unicode'
-            digest = hmac.new(str(key), msg.encode('utf-8'), hashlib.sha1).hexdigest()
+            digest = hmac.new(str(key), msg.encode('utf-8'), sha).hexdigest()
 
             if digest != auth['value']:
                 raise PLCAuthenticationFailure, "Call could not be authenticated"
index 59ff6dd..be3f2d3 100644 (file)
 
 from types import StringTypes
 from datetime import datetime
-import hashlib
+try:
+    from hashlib import md5
+except ImportError:
+    from md5 import md5
 import time
 from random import Random
 import re
@@ -116,7 +119,7 @@ class Person(Row):
         else:
             # Generate a somewhat unique 8 character salt string
             salt = str(time.time()) + str(Random().random())
-            salt = hashlib.md5(salt).hexdigest()[:8] 
+            salt = md5(salt).hexdigest()[:8] 
             return crypt.crypt(password.encode(self.api.encoding), magic + salt + "$")
 
     validate_date_created = Row.validate_timestamp