????

Your IP : 3.23.61.5


Current Path : /lib/python3.6/site-packages/glances/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/glances/__pycache__/password.cpython-36.pyc

3

Eo�c�@s�dZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
ddlmZddl
mZddlmZGdd	�d	e�ZdS)
zManage password.�N)�open)�b�input)�user_config_dir)�
safe_makedirs)�loggerc@s\eZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	ddd�Z
dd�Zdd�ZdS)�GlancesPasswordz9This class contains all the methods relating to password.�glancesNcCs:||_||_|j�|_|jd|_tjj|j|j�|_dS)Nz.pwd)	�username�config�local_password_path�password_dirZpassword_filename�os�path�join�
password_file)�selfr
r�r�/usr/lib/python3.6/password.py�__init__s

zGlancesPassword.__init__cCs(|jdkrt�S|jjddt�d�SdS)zzReturn the local password path.
        Related toissue: Password files in same configuration dir in effect #2143
        NZ	passwordsr)�default)rrZ	get_value)rrrrr%s
z#GlancesPassword.local_password_pathcCstjt|��j�S)z)Return the SHA-256 of the given password.)�hashlib�sha256r�	hexdigest)r�plain_passwordrrr�sha256_hash.szGlancesPassword.sha256_hashcCstj|j�|j��j�S)z+Return the hashed password, salt + SHA-256.)rr�encoder)r�saltrrrr�get_hash2szGlancesPassword.get_hashcCs"tj�j}|j||�}|d|S)zHHash password with a salt based on UUID (universally unique identifier).�$)�uuidZuuid4�hexr)rrr�encrypted_passwordrrr�
hash_password6s
zGlancesPassword.hash_passwordcCs"|jd�\}}|j||�}||kS)z�Encode the plain_password with the salt of the hashed_password.

        Return the comparison with the encrypted_password.
        r)�splitr)r�hashed_passwordrrr"Zre_encrypted_passwordrrr�check_password<szGlancesPassword.check_password�Fc	Cs�tjj|j�r0|r0tjdj|j��|j�}n�|jt	j	|��}|j
|�}|r~|jt	j	d��}|j||�s~tjd�t
jd�|r�|}n|}|s�td�}t|�dkr�|dj�dkr�|j|�|S)a�Get the password from a Glances client or server.

        For Glances server, get the password (confirm=True, clear=False):
            1) from the password file (if it exists)
            2) from the CLI
        Optionally: save the password to a file (hashed with salt + SHA-256)

        For Glances client, get the password (confirm=False, clear=True):
            1) from the CLI
            2) the password is hashed with SHA-256 (only SHA string transit
               through the network)
        zRead password from file {}zPassword (confirm): z$Sorry, passwords do not match. Exit.�z,Do you want to save the password? [Yes/No]: r�Y)rr�existsrr�info�format�
load_passwordr�getpassr#r&Zcritical�sys�exitr�len�upper�
save_password)	r�descriptionZconfirm�clearZpasswordZpassword_sha256Zpassword_hashedZpassword_confirmZ
save_inputrrr�get_passwordEs$





zGlancesPassword.get_passwordc
Cs4t|j�t|jd��}|jt|��WdQRXdS)z/Save the hashed password to the Glances folder.�wbN)rr
rr�writer)rr%�file_pwdrrrr3qs
zGlancesPassword.save_passwordc	Cs$t|jd��}|j�}WdQRX|S)z1Load the hashed password from the Glances folder.�rN)rr�read)rr9r%rrrr-zszGlancesPassword.load_password)r	N)r'FF)
�__name__�
__module__�__qualname__�__doc__rrrrr#r&r6r3r-rrrrrs
		
,	r)r?r.rrr/r �iorZglances.compatrrZglances.configrZglances.globalsrZglances.loggerr�objectrrrrr�<module>
s