diff options
Diffstat (limited to 'glances/password.py')
-rw-r--r-- | glances/password.py | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/glances/password.py b/glances/password.py index 6e1d6ad8..fdaea71a 100644 --- a/glances/password.py +++ b/glances/password.py @@ -1,28 +1,26 @@ -# -*- coding: utf-8 -*- # # This file is part of Glances. # -# SPDX-FileCopyrightText: 2023 Nicolas Hennion <nicolas@nicolargo.com> +# SPDX-FileCopyrightText: 2024 Nicolas Hennion <nicolas@nicolargo.com> # # SPDX-License-Identifier: LGPL-3.0-only # """Manage password.""" +import builtins import getpass import hashlib import os import sys import uuid -from io import open -from glances.globals import b, safe_makedirs, weak_lru_cache from glances.config import user_config_dir +from glances.globals import b, safe_makedirs, weak_lru_cache from glances.logger import logger -class GlancesPassword(object): - +class GlancesPassword: """This class contains all the methods relating to password.""" def __init__(self, username='glances', config=None): @@ -39,8 +37,7 @@ class GlancesPassword(object): """ if self.config is None: return user_config_dir()[0] - else: - return self.config.get_value('passwords', 'local_password_path', default=user_config_dir()[0]) + return self.config.get_value('passwords', 'local_password_path', default=user_config_dir()[0]) @weak_lru_cache(maxsize=32) def get_hash(self, plain_password, salt=''): @@ -60,7 +57,6 @@ class GlancesPassword(object): 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 @@ -80,7 +76,7 @@ class GlancesPassword(object): """ if os.path.exists(self.password_file) and not clear: # If the password file exist then use it - logger.info("Read password from file {}".format(self.password_file)) + logger.info(f"Read password from file {self.password_file}") password = self.load_password() else: # password_hash is the plain SHA-pbkdf2_hmac password @@ -115,13 +111,11 @@ class GlancesPassword(object): safe_makedirs(self.password_dir) # Create/overwrite the password file - with open(self.password_file, 'wb') as file_pwd: + with builtins.open(self.password_file, 'wb') as file_pwd: file_pwd.write(b(hashed_password)) def load_password(self): """Load the hashed password from the Glances folder.""" # Read the password file, if it exists - with open(self.password_file, 'r') as file_pwd: - hashed_password = file_pwd.read() - - return hashed_password + with builtins.open(self.password_file) as file_pwd: + return file_pwd.read() |