%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/passlib/handlers/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/passlib/handlers/__pycache__/django.cpython-39.pyc

a

f�Wc�N�@s�dZddlmZddlmZddlmZmZmZddl	Z	e	�
e�Zddl
mZddlmZmZmZmZddlmZmZmZdd	lmZdd
lmZmZmZmZddlm Z ddl!m"m#Z$gd�Z%da&d
d�Z'dZ(Gdd�de$j)e$j*�Z+Gdd�de$j,e+�Z-Gdd�de+�Z.Gdd�de+�Z/e$j0deed�ed�dd�Z1de1_2e1j3d7_3Gdd�de�Z4Gd d!�d!e-�Z5Gd"d#�d#e5�Z6e$j0d$ej7d%d&�ed'�ed(�d)d*�Z8d'e8_2e8j3d7_3Gd+d,�d,e$j9e$j)e$j*�Z:Gd-d.�d.e$j;j<e$j=�Z>dS)/z5passlib.handlers.django- Django password hash support�)�	b64encode)�hexlify)�md5�sha1�sha256N)�_wrapped_bcrypt)�argon2�bcrypt�pbkdf2_sha1�
pbkdf2_sha256)�
to_unicode�rng�
getrandstr)�BASE64_CHARS)�
str_to_uascii�
uascii_to_str�unicode�u)�pbkdf2_hmac)�django_salted_sha1�django_salted_md5�
django_bcrypt�django_pbkdf2_sha1�django_pbkdf2_sha256�
django_argon2�django_des_crypt�django_disabledcCstdurddlmatS)Nr)�	des_crypt)r�passlib.hash�rr�;/usr/lib/python3.9/site-packages/passlib/handlers/django.py�_import_des_crypt&sr!Z>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789c@s:eZdZdZdZdZdZeZe	j
Zedd��Z
dd�ZdS)	�DjangoSaltedHashz2base class providing common code for django hashes)�salt�	salt_size�NcCs"tj||j|d�\}}|||d�S)N�Zhandler�r#�checksum)�uh�	parse_mc2�ident��cls�hashr#�chkrrr �from_stringBszDjangoSaltedHash.from_stringcCst�|j|j|j�S�N)r)�
render_mc2r+r#r(��selfrrr �	to_stringGszDjangoSaltedHash.to_string)�__name__�
__module__�__qualname__�__doc__�setting_kwds�default_salt_sizeZ
max_salt_size�
SALT_CHARS�
salt_charsr)ZLOWER_HEX_CHARS�checksum_chars�classmethodr0r5rrrr r"2s
r"c@s2eZdZdZejdZdZedd��Zdd�Z	dS)	�DjangoVariableHashzEbase class providing common code for django hashes w/ variable rounds)�rounds�cCs&tj||j|d�\}}}||||d�S)Nr&)rAr#r()r)Z	parse_mc3r+)r-r.rAr#r/rrr r0QszDjangoVariableHash.from_stringcCst�|j|j|j|j�Sr1)r)Z
render_mc3r+rAr#r(r3rrr r5VszDjangoVariableHash.to_stringN)
r6r7r8r9r"r:Z
min_roundsr?r0r5rrrr r@Ks

r@c@s,eZdZdZdZdZed�ZdZdd�Z	dS)ra�This class implements Django's Salted SHA1 hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, and uses a single round of SHA1.

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, a 12 character one will be autogenerated (this is recommended).
        If specified, may be any series of characters drawn from the regexp range ``[0-9a-zA-Z]``.

    :type salt_size: int
    :param salt_size:
        Optional number of characters to use when autogenerating new salts.
        Defaults to 12, but can be any positive value.

    This should be compatible with Django 1.4's :class:`!SHA1PasswordHasher` class.

    .. versionchanged: 1.6
        This class now generates 12-character salts instead of 5,
        and generated salts uses the character range ``[0-9a-zA-Z]`` instead of
        the ``[0-9a-f]``. This is to be compatible with how Django >= 1.4
        generates these hashes; but hashes generated in this manner will still be
        correctly interpreted by earlier versions of Django.
    rzsha1$�(cCs0t|t�r|�d�}tt|j�d�|����S�N�utf-8�ascii)�
isinstancer�encoderrr#�	hexdigest�r4�secretrrr �_calc_checksumys

z!django_salted_sha1._calc_checksumN�
r6r7r8r9�name�django_namerr+�
checksum_sizerLrrrr rYsrc@s,eZdZdZdZdZed�ZdZdd�Z	dS)ra�This class implements Django's Salted MD5 hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, and uses a single round of MD5.

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, a 12 character one will be autogenerated (this is recommended).
        If specified, may be any series of characters drawn from the regexp range ``[0-9a-zA-Z]``.

    :type salt_size: int
    :param salt_size:
        Optional number of characters to use when autogenerating new salts.
        Defaults to 12, but can be any positive value.

    This should be compatible with the hashes generated by
    Django 1.4's :class:`!MD5PasswordHasher` class.

    .. versionchanged: 1.6
        This class now generates 12-character salts instead of 5,
        and generated salts uses the character range ``[0-9a-zA-Z]`` instead of
        the ``[0-9a-f]``. This is to be compatible with how Django >= 1.4
        generates these hashes; but hashes generated in this manner will still be
        correctly interpreted by earlier versions of Django.
    rzmd5$� cCs0t|t�r|�d�}tt|j�d�|����SrD)rGrrHrrr#rIrJrrr rL�s

z django_salted_md5._calc_checksumNrMrrrr r~srrzbcrypt$a�This class implements Django 1.4's BCrypt wrapper, and follows the :ref:`password-hash-api`.

    This is identical to :class:`!bcrypt` itself, but with
    the Django-specific prefix ``"bcrypt$"`` prepended.

    See :doc:`/lib/passlib.hash.bcrypt` for more details,
    the usage and behavior is identical.

    This should be compatible with the hashes generated by
    Django 1.4's :class:`!BCryptPasswordHasher` class.

    .. versionadded:: 1.6
    )�prefixr+�docr	)rOcs\eZdZdZdZdZeZed�Z	e
dd��Ze
�fdd��Z�fdd	�Z
�fd
d�Z�ZS)�django_bcrypt_sha256a�This class implements Django 1.6's Bcrypt+SHA256 hash, and follows the :ref:`password-hash-api`.

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

    While the algorithm and format is somewhat different,
    the api and options for this hash are identical to :class:`!bcrypt` itself,
    see :doc:`bcrypt </lib/passlib.hash.bcrypt>` for more details.

    .. versionadded:: 1.6.2
    Z
bcrypt_sha256zbcrypt_sha256$cCst�|�}|sdS|�|j�S�NF)r)�to_unicode_for_identify�
startswith�
django_prefix�r-r.rrr �identify�s
zdjango_bcrypt_sha256.identifycs\t|dd�}|�|j�s$tj�|��|t|j�d�}|�d�sLtj�|��tt	|��
|�S)NrFr.z$2)rrWrXr)�exc�InvalidHashError�len�MalformedHashError�superrTr0)r-r.�bhash��	__class__rr r0�s
z django_bcrypt_sha256.from_stringcstt|���}t|j�|Sr1)r_rTr5rrX)r4r`rarr r5�szdjango_bcrypt_sha256.to_stringcs6t|t�r|�d�}t|�|����}tt|��|�S)NrE)	rGrrHr�_digest�digestr_rTrLrJrarr rL�s

z#django_bcrypt_sha256._calc_checksum)r6r7r8r9rNrOrrcrrXr?rZr0r5rL�
__classcell__rrrar rT�s

	rTc@sDeZdZdZdZdZed�ZdZdZ	e
jZdZ
ejZdZdd	�Zd
S)ra�This class implements Django's PBKDF2-HMAC-SHA256 hash, and follows the :ref:`password-hash-api`.

    It supports a variable-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, a 12 character one will be autogenerated (this is recommended).
        If specified, may be any series of characters drawn from the regexp range ``[0-9a-zA-Z]``.

    :type salt_size: int
    :param salt_size:
        Optional number of characters to use when autogenerating new salts.
        Defaults to 12, but can be any positive value.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 29000, but must be within ``range(1,1<<32)``.

    :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.

    This should be compatible with the hashes generated by
    Django 1.4's :class:`!PBKDF2PasswordHasher` class.

    .. versionadded:: 1.6
    rzpbkdf2_sha256$rBl���,rcCs&t|j||j|j�}t|����d�S)NrF)rrcr#rAr�rstrip�decode)r4rKr.rrr rL#sz#django_pbkdf2_sha256._calc_checksumN)r6r7r8r9rNrOrr+�
min_salt_sizeZ
max_roundsr)ZPADDED_BASE64_CHARSr>rPr�default_roundsrcrLrrrr r�s#rc@s.eZdZdZdZdZed�ZdZe	j
Z
dZdS)ra�This class implements Django's PBKDF2-HMAC-SHA1 hash, and follows the :ref:`password-hash-api`.

    It supports a variable-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, a 12 character one will be autogenerated (this is recommended).
        If specified, may be any series of characters drawn from the regexp range ``[0-9a-zA-Z]``.

    :type salt_size: int
    :param salt_size:
        Optional number of characters to use when autogenerating new salts.
        Defaults to 12, but can be any positive value.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 131000, but must be within ``range(1,1<<32)``.

    :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.

    This should be compatible with the hashes generated by
    Django 1.4's :class:`!PBKDF2SHA1PasswordHasher` class.

    .. versionadded:: 1.6
    r
zpbkdf2_sha1$�rN)r6r7r8r9rNrOrr+rPr
rjrcrrrr r(s#rr�I)�typerzargon2$argon2i$a�This class implements Django 1.10's Argon2 wrapper, and follows the :ref:`password-hash-api`.

    This is identical to :class:`!argon2` itself, but with
    the Django-specific prefix ``"argon2$"`` prepended.

    See :doc:`argon2 </lib/passlib.hash.argon2>` for more details,
    the usage and behavior is identical.

    This should be compatible with the hashes generated by
    Django 1.10's :class:`!Argon2PasswordHasher` class.

    .. versionadded:: 1.7
    )rN�wrappedrRr+rSc@s^eZdZdZdZdZdZed�Ze	j
ZZdZ
dZZdZdZed	d
��Zdd�Zd
d�ZdS)ra�This class implements Django's :class:`des_crypt` wrapper, and follows the :ref:`password-hash-api`.

    It supports a fixed-length salt.

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept 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 2 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :param bool truncate_error:
        By default, django_des_crypt will silently truncate passwords larger than 8 bytes.
        Setting ``truncate_error=True`` will cause :meth:`~passlib.ifc.PasswordHash.hash`
        to raise a :exc:`~passlib.exc.PasswordTruncateError` instead.

        .. versionadded:: 1.7

    This should be compatible with the hashes generated by
    Django 1.4's :class:`!CryptPasswordHasher` class.
    Note that Django only supports this hash on Unix systems
    (though :class:`!django_des_crypt` is available cross-platform
    under Passlib).

    .. versionchanged:: 1.6
        This class will now accept hashes with empty salt strings,
        since Django 1.4 generates them this way.
    Zcrypt)r#r$Ztruncate_errorzcrypt$���TcCsjtj||j|d�\}}|r^|s,|dd�}n&|dd�|dd�krRtj�|d��|dd�}|||d�S)Nr&rpz0first two digits of salt and checksum must matchr')r)r*r+r[r^r,rrr r0�s�zdjango_des_crypt.from_stringcCsB|j}|dd�|j}|jr.t�|j||�St�|jd|�SdS)Nrp�)r#r(�use_duplicate_saltr)r2r+)r4r#r/rrr r5�s
zdjango_des_crypt.to_stringcCs8tdurt�|jr|�|�t|jdd�d��|�S)Nrp)r#)rr!Zuse_defaultsZ_check_truncate_policyr#rLrJrrr rL�s

zdjango_des_crypt._calc_checksumN)r6r7r8r9rNrOr:rr+r)ZHASH64_CHARSr>r=rPrir;Z
truncate_sizersr?r0r5rLrrrr rts


rc@s@eZdZdZdZed�ZdZedd��Z	dd�Z
edd	��Zd
S)raFThis class provides disabled password behavior for Django, and follows the :ref:`password-hash-api`.

    This class does not implement a hash, but instead
    claims the special hash string ``"!"`` which Django uses
    to indicate an account's password has been disabled.

    * newly encrypted passwords will hash to ``"!"``.
    * it rejects all passwords.

    .. note::

        Django 1.6 prepends a randomly generated 40-char alphanumeric string
        to each unusuable password. This class recognizes such strings,
        but for backwards compatibility, still returns ``"!"``.

        See `<https://code.djangoproject.com/ticket/20079>`_ for why
        Django appends an alphanumeric string.

    .. versionchanged:: 1.6.2 added Django 1.6 support

    .. versionchanged:: 1.7 started appending an alphanumeric string.
    �!rCcCst�|�}|�|j�Sr1)r)rVrW�_hash_prefixrYrrr rZ�s
zdjango_disabled.identifycCstttdd�|j�S)N���)rr
r�
suffix_lengthrJrrr rL�szdjango_disabled._calc_checksumcCs$t�|�|�|�s tj�|��dSrU)r)Zvalidate_secretrZr[r\)r-rKr.rrr �verify�s

zdjango_disabled.verifyN)r6r7r8r9rNrrurwr?rZrLrxrrrr r�s
r)?r9�base64rZbinasciirZhashlibrrrZloggingZ	getLoggerr6�logZpasslib.handlers.bcryptrrrr	r
rZ
passlib.utilsrr
rZpasslib.utils.binaryrZpasslib.utils.compatrrrrZpasslib.crypto.digestrZpasslib.utils.handlersZutils�handlersr)�__all__rr!r<ZHasSaltZGenericHandlerr"Z	HasRoundsr@rrZ
PrefixWrapperrrOZ_using_clone_attrsrTrrZusingrZ
TruncateMixinrZifcZDisabledHashZ
StaticHandlerrrrrr �<module>sN%*�532
�^

Zerion Mini Shell 1.0