[FIX] core, base: CryptContext.encrypt is deprecated

However encrypt was marked as deprecated in the same version hash
was added, so we need a conditional check to support <= 1.6.
This commit is contained in:
Xavier Morel
2020-02-04 12:42:35 +00:00
parent de590816d8
commit 672709c125
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -296,8 +296,9 @@ class Users(models.Model):
def _set_password(self):
ctx = self._crypt_context()
hash_password = ctx.hash if hasattr(ctx, 'hash') else ctx.encrypt
for user in self:
self._set_encrypted_password(user.id, ctx.encrypt(user.password))
self._set_encrypted_password(user.id, hash_password(user.password))
def _set_encrypted_password(self, uid, pw):
assert self._crypt_context().identify(pw) != 'plaintext'
+2 -1
View File
@@ -694,7 +694,8 @@ class configmanager(object):
return os.path.join(self['data_dir'], 'filestore', dbname)
def set_admin_password(self, new_password):
self.options['admin_passwd'] = crypt_context.encrypt(new_password)
hash_password = crypt_context.hash if hasattr(crypt_context, 'hash') else crypt_context.encrypt
self.options['admin_passwd'] = hash_password(new_password)
def verify_admin_password(self, password):
"""Verifies the super-admin password, possibly updating the stored hash if needed"""