§
    HŠtj±  ã                   óÀ   — d Z ddlmZ ddlZ ej        e¦  «        ZddlmZ ddl	m
Z
mZmZ ddlmc mZ dgZ G d„ dej        ej        ej        ej        ¦  «        ZdS )zÝpasslib.handlers.phpass - PHPass Portable Crypt

phppass located - http://www.openwall.com/phpass/
algorithm described - http://www.openwall.com/articles/PHP-Users-Passwords

phpass context - blowfish, bsdi_crypt, phpass
é    )Úmd5N)Úh64)ÚuÚuascii_to_strÚunicodeÚphpassc                   ó  — e Zd ZdZd ZdZej        ZdxZ	Z
ej        ZdZdZdZdZ ed¦  «        Z ed¦  «         ed	¦  «        fZ ed
¦  «         ed¦  «         ed¦  «         ed	¦  «        iZed„ ¦   «         Zd„ Zd„ ZdS )r   a€  This class implements the PHPass Portable Hash, and follows the :ref:`password-hash-api`.

    It supports a fixed-length salt, and a variable number of rounds.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 8 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 19, must be between 7 and 30, inclusive.
        This value is logarithmic, the actual number of iterations used will be :samp:`2**{rounds}`.

    :type ident: str
    :param ident:
        phpBB3 uses ``H`` instead of ``P`` for its identifier,
        this may be set to ``H`` in order to generate phpBB3 compatible hashes.
        it defaults to ``P``.

    :type relaxed: bool
    :param relaxed:
        By default, providing an invalid value for one of the other
        keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
        and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
        will be issued instead. Correctable errors include ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6
    )ÚsaltÚroundsÚidenté   é   é   é   Úlog2z$P$z$H$ÚPÚHc                 óÖ   — |                       |¦  «        \  }}|d         |dd…         |dd …         }}} | |t          j        |                     d¦  «        ¦  «        ||pd ¬¦  «        S )Nr   é   é	   Úascii)r   r   r
   Úchecksum)Ú_parse_identr   Údecode_int6Úencode)ÚclsÚhashr   Údatar   r
   Úchks          úU/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/passlib/handlers/phpass.pyÚfrom_stringzphpass.from_string`   sy   € à×&Ò& tÑ,Ô,‰ˆˆtØ  œG T¨!¨A¨#¤Y°°Q°R°R´�c�ˆØˆsØÝ”? 6§=¢=°Ñ#9Ô#9Ñ:Ô:ØØ�[˜Dð	
ñ 
ô 
ð 	
ó    c                 óÜ   — t          d¦  «        | j        t          j        | j        ¦  «                             d¦  «        | j        | j        pt          d¦  «        fz  }t          |¦  «        S )Nz%s%s%s%sr   Ú )	r   r   r   Úencode_int6r   Údecoder
   r   r   )Úselfr   s     r    Ú	to_stringzphpass.to_stringk   s]   € Ý�‰}Œ} ¤
Ý!œo¨d¬kÑ:Ô:×AÒAÀ'ÑJÔJØ"œiØ"œmÐ4­q°©u¬uð 6ñ 6ˆõ ˜TÑ"Ô"Ð"r"   c                 óž  — t          |t          ¦  «        r|                     d¦  «        }d| j        z  }t	          | j                             d¦  «        |z   ¦  «                             ¦   «         }d}||k     r/t	          ||z   ¦  «                             ¦   «         }|dz  }||k     °/t          j        |¦  «         	                    d¦  «        S )Nzutf-8r   r   r   )
Ú
isinstancer   r   r   r   r
   Údigestr   Úencode_bytesr&   )r'   ÚsecretÚreal_roundsÚresultÚrs        r    Ú_calc_checksumzphpass._calc_checksumu   s¾   € å�f�gÑ&Ô&ð 	,Ø—]’] 7Ñ+Ô+ˆFØ˜œ‘nˆÝ�T”Y×%Ò% gÑ.Ô.°Ñ7Ñ8Ô8×?Ò?ÑAÔAˆØˆØ�+ŠoˆoÝ˜ &™Ñ)Ô)×0Ò0Ñ2Ô2ˆFØ�‰FˆAð �+Šoˆoõ Ô Ñ'Ô'×.Ò.¨wÑ7Ô7Ð7r"   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚsetting_kwdsÚuhÚHASH64_CHARSÚchecksum_charsÚmin_salt_sizeÚmax_salt_sizeÚ
salt_charsÚdefault_roundsÚ
min_roundsÚ
max_roundsÚrounds_costr   Údefault_identÚident_valuesÚident_aliasesÚclassmethodr!   r(   r1   © r"   r    r   r      së   € € € € € ð!ð !ðN €DØ.€LØ”_€Nð %&Ð%€M�MØ”€Jð €NØ€JØ€JØ€Kð �A�e‘H”H€MØ�A�e‘H”H˜a˜a ™hœhÐ'€LØ�Q�s‘V”V˜A˜A˜e™HœH a a¨¡f¤f¨Q¨Q¨u©X¬XÐ6€Mð ð
ð 
ñ „[ð
ð#ð #ð #ð
8ð 
8ð 
8ð 
8ð 
8r"   )r5   Úhashlibr   ÚloggingÚ	getLoggerr2   ÚlogÚpasslib.utils.binaryr   Úpasslib.utils.compatr   r   r   Úpasslib.utils.handlersÚutilsÚhandlersr8   Ú__all__ÚHasManyIdentsÚ	HasRoundsÚHasSaltÚGenericHandlerr   rF   r"   r    ú<module>rU      så   ððð ð Ð Ð Ð Ð Ð Ø €€€Ð'�gÔ'¨Ñ1Ô1�ð %Ð $Ð $Ð $Ð $Ð $Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ð #ð ð€ðd8ð d8ð d8ð d8ð d8ˆRÔ˜rœ|¨R¬Z¸Ô9Jñ d8ô d8ð d8ð d8ð d8r"   