diff options
author | nicolargo <nicolas@nicolargo.com> | 2023-12-21 15:53:27 +0100 |
---|---|---|
committer | nicolargo <nicolas@nicolargo.com> | 2023-12-21 15:53:27 +0100 |
commit | 70250981b9ebabd3212c9e3d01c1fced49e1a33e (patch) | |
tree | 09569f96e0a7c0dfa2cd851e597f96379964e8a4 /glances/password.py | |
parent | e936a38dde886f151d75977b4ec947a8f5da2259 (diff) | |
parent | 380888a5648d914439f9b221dfd5ce589b2ffd54 (diff) |
Merge branch 'develop' into issue2183issue2183
Diffstat (limited to 'glances/password.py')
-rw-r--r-- | glances/password.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/glances/password.py b/glances/password.py index 782e6102..4b06047d 100644 --- a/glances/password.py +++ b/glances/password.py @@ -2,7 +2,7 @@ # # This file is part of Glances. # -# SPDX-FileCopyrightText: 2022 Nicolas Hennion <nicolas@nicolargo.com> +# SPDX-FileCopyrightText: 2023 Nicolas Hennion <nicolas@nicolargo.com> # # SPDX-License-Identifier: LGPL-3.0-only # @@ -16,7 +16,7 @@ import sys import uuid from io import open -from glances.globals import b, safe_makedirs +from glances.globals import b, safe_makedirs, weak_lru_cache from glances.config import user_config_dir from glances.logger import logger @@ -42,21 +42,25 @@ class GlancesPassword(object): else: return self.config.get_value('passwords', 'local_password_path', default=user_config_dir()) + @weak_lru_cache(maxsize=32) def get_hash(self, plain_password, salt=''): """Return the hashed password, salt + pbkdf2_hmac.""" return hashlib.pbkdf2_hmac('sha256', plain_password.encode(), salt.encode(), 100000, dklen=128).hex() + @weak_lru_cache(maxsize=32) def hash_password(self, plain_password): """Hash password with a salt based on UUID (universally unique identifier).""" salt = uuid.uuid4().hex encrypted_password = self.get_hash(plain_password, salt=salt) return salt + '$' + encrypted_password + @weak_lru_cache(maxsize=32) def check_password(self, hashed_password, plain_password): """Encode the plain_password with the salt of the hashed_password. Return the comparison with the encrypted_password. """ + logger.info("Check password") salt, encrypted_password = hashed_password.split('$') re_encrypted_password = self.get_hash(plain_password, salt=salt) return encrypted_password == re_encrypted_password |