[server/utils] passlib 1.6 is now less tolerant wrt handler names (closes #2349330) stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 11 May 2012 10:08:58 +0200
branchstable
changeset 8398 a9fe30c953be
parent 8395 41729460d8c3
child 8399 0ea4ccf1d9a6
child 8402 efafa1261477
[server/utils] passlib 1.6 is now less tolerant wrt handler names (closes #2349330)
server/utils.py
--- a/server/utils.py	Thu May 10 10:33:42 2012 +0200
+++ b/server/utils.py	Fri May 11 10:08:58 2012 +0200
@@ -20,13 +20,9 @@
 __docformat__ = "restructuredtext en"
 
 import sys
-import string
 import logging
 from threading import Timer, Thread
 from getpass import getpass
-from random import choice
-
-from cubicweb.server import SOURCE_TYPES
 
 from passlib.utils import handlers as uh, to_hash_str
 from passlib.context import CryptContext
@@ -35,8 +31,8 @@
 
 
 class CustomMD5Crypt(uh.HasSalt, uh.GenericHandler):
-    name = 'cubicweb-md5crypt'
-    setting_kwds = ("salt",)
+    name = 'cubicwebmd5crypt'
+    setting_kwds = ('salt',)
     min_salt_size = 0
     max_salt_size = 8
     salt_chars = uh.H64_CHARS
@@ -57,17 +53,17 @@
     def calc_checksum(self, secret):
         return md5crypt(secret, self.salt.encode('ascii'))
 
-myctx = CryptContext(['sha512_crypt', CustomMD5Crypt, 'des_crypt'])
+_CRYPTO_CTX = CryptContext(['sha512_crypt', CustomMD5Crypt, 'des_crypt'])
 
 def crypt_password(passwd, salt=None):
     """return the encrypted password using the given salt or a generated one
     """
     if salt is None:
-        return myctx.encrypt(passwd)
+        return _CRYPTO_CTX.encrypt(passwd)
     # empty hash, accept any password for backwards compat
     if salt == '':
         return salt
-    if myctx.verify(passwd, salt):
+    if _CRYPTO_CTX.verify(passwd, salt):
         return salt
     # wrong password
     return ''