
    Mh                         d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZmZ dZdd	Zd
 Ze	dd            ZddZdS )z-
Password generation for the Jupyter Server.
    N)contextmanager)jupyter_config_dir)Config)ConfigFileNotFoundJSONFileConfigLoader   argon2c                    | kt          d          D ]J}t          j        d          }t          j        d          }||k    r|}  n(t          j        dd           Kd}t	          |          |d	k    r8d
dl}|                    ddd          }|                    |           }| d| S t          j	        |          }	dt          t                    z   dz   t          j        dt          z            z  }
|	                    |                     d          |
                    d          z              | d|
 d|	                                 S )a  Generate hashed password and salt for use in server configuration.

    In the server configuration, set `c.ServerApp.password` to
    the generated string.

    Parameters
    ----------
    passphrase : str
        Password to hash.  If unspecified, the user is asked to input
        and verify a password.
    algorithm : str
        Hashing algorithm to use (e.g, 'sha1' or any argument supported
        by :func:`hashlib.new`, or 'argon2').

    Returns
    -------
    hashed_passphrase : str
        Hashed password, in the format 'hash_algorithm:salt:passphrase_hash'.

    Examples
    --------
    >>> passwd("mypassword")  # doctest: +ELLIPSIS
    'argon2:...'

    N   zEnter password: zVerify password: zPasswords do not match.   
stacklevelz'No matching passwords found. Giving up.r	   r   i (  
      )memory_cost	time_costparallelism:z%0x   utf-8ascii)rangegetpasswarningswarn
ValueErrorr	   PasswordHasherhashhashlibnewstrsalt_lenrandomgetrandbitsupdateencode	hexdigest)
passphrase	algorithm_p0p1msgr	   phh_phhsalts              \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyter_server/auth/security.pypasswdr4      sg   4 q 		" 		"A!344B!455BRxx
M3BBBBB;CS//!H"" # 
 

 wwz""$$d$$$IA3x== 3&&*<Q\*J*JJDHHZw''$++g*>*>>???00$00000    c                 Z   |                      d          rQddl}ddl}|                                }	 |                    | dd         |          S # |j        j        $ r Y dS w xY w	 |                     dd          \  }}}n# t          t          f$ r Y dS w xY w	 t          j        |          }n# t          $ r Y dS w xY wt          |          dk    rdS |                    |                    d          |                    d	          z              |                                |k    S )
a`  Verify that a given passphrase matches its hashed version.

    Parameters
    ----------
    hashed_passphrase : str
        Hashed password, in the format returned by `passwd`.
    passphrase : str
        Passphrase to validate.

    Returns
    -------
    valid : bool
        True if the passphrase matches the hash.

    Examples
    --------
    >>> myhash = passwd("mypassword")
    >>> passwd_check(myhash, "mypassword")
    True

    >>> passwd_check(myhash, "otherpassword")
    False

    >>> passwd_check("sha1:0e112c3ddfce:a68df677475c2b47b6e86d0467eec97ac5f4b85a", "mypassword")
    True
    zargon2:r   N   Fr   r   r   r   )
startswithr	   argon2.exceptionsr   verify
exceptionsVerificationErrorsplitr   	TypeErrorr    r!   lenr&   r'   r(   )hashed_passphraser)   r	   r/   r*   r2   	pw_digestr1   s           r3   passwd_checkrB   P   si   6 ##I.. 	    ""$$	99.qrr2J??? 2 	 	 	55	%6%<%<S!%D%D"	4	"   uuK	""   uu 9~~uHHZw''$++g*>*>>???;;==I%%s5   A A$#A$(B BBB1 1
B?>B?  c              #   .  K   | ,t           j                            t                      d          } t          j        t           j                            |           d           t          t           j                            |           t           j                            |                     }	 |                                }n# t          $ r t                      }Y nw xY w|V  t          | dd          5 }|                    t          j        |d	                     ddd           n# 1 swxY w Y   	 t          j        | |           dS # t           $ r9 t#          j                    }t'          j        d
|  d| t*          d           Y dS w xY w)zContext manager that can be used to modify a config object

    On exit of the context manager, the config will be written back to disk,
    by default with user-only (600) permissions.
    Nzjupyter_server_config.jsonT)exist_okwutf8)encodingr   )indentzFailed to set permissions on z:
r   )ospathjoinr   makedirsdirnamer   basenameload_configr   r   openwritejsondumpschmod	Exception	traceback
format_excr   r   RuntimeWarning)config_filemodeloaderconfigftbs         r3   persist_configr`      s      gll#5#7#79UVVK,,t<<<<!"'"2"2;"?"?Q\A]A]^^F##%%    LLL	k3	0	0	0 .A	
6!,,,---. . . . . . . . . . . . . . .

d##### 
 
 
!##@K@@B@@.]^	
 	
 	
 	
 	
 	
 	

s6   /C CC8*D..D25D2:E ?FFc                     t          |           }t          |          5 }||j        _        ddd           n# 1 swxY w Y   |S )z:Ask user for password, store it in JSON configuration fileN)r4   r`   IdentityProviderhashed_password)passwordrZ   rc   r]   s       r3   set_passwordre      s     X&&O		$	$ B2A/B B B B B B B B B B B B B B Bs   8<<)Nr	   )NrC   )NN)__doc__r   r    rS   rJ   r$   rW   r   
contextlibr   jupyter_core.pathsr   traitlets.configr   traitlets.config.loaderr   r   r#   r4   rB   r`   re    r5   r3   <module>rl      s       				       % % % % % % 1 1 1 1 1 1 # # # # # # L L L L L L L L 61 61 61 61r5& 5& 5&p 
 
 
 
@     r5   