52 return cls(salt=salt, checksum=chk) |
52 return cls(salt=salt, checksum=chk) |
53 |
53 |
54 def to_string(self): |
54 def to_string(self): |
55 return to_hash_str(u'%s$%s' % (self.salt, self.checksum or u'')) |
55 return to_hash_str(u'%s$%s' % (self.salt, self.checksum or u'')) |
56 |
56 |
57 # passlib 1.5 wants calc_checksum, 1.6 wants _calc_checksum |
57 def _calc_checksum(self, secret): |
58 def calc_checksum(self, secret): |
|
59 return md5crypt(secret, self.salt.encode('ascii')).decode('utf-8') |
58 return md5crypt(secret, self.salt.encode('ascii')).decode('utf-8') |
60 _calc_checksum = calc_checksum |
|
61 |
59 |
62 |
60 |
63 _CRYPTO_CTX = CryptContext(['sha512_crypt', CustomMD5Crypt, 'des_crypt', 'ldap_salted_sha1'], |
61 _CRYPTO_CTX = CryptContext(['sha512_crypt', CustomMD5Crypt, 'des_crypt', 'ldap_salted_sha1'], |
64 deprecated=['cubicwebmd5crypt', 'des_crypt']) |
62 deprecated=['cubicwebmd5crypt', 'des_crypt']) |
|
63 # for bw compat with passlib < 1.7 |
|
64 if not hasattr(_CRYPTO_CTX, 'hash'): |
|
65 _CRYPTO_CTX.hash = _CRYPTO_CTX.encrypt |
65 verify_and_update = _CRYPTO_CTX.verify_and_update |
66 verify_and_update = _CRYPTO_CTX.verify_and_update |
66 |
67 |
67 |
68 |
68 def crypt_password(passwd, salt=None): |
69 def crypt_password(passwd, salt=None): |
69 """return the encrypted password using the given salt or a generated one |
70 """return the encrypted password using the given salt or a generated one |