
     hN                        d Z ddlmZ ddlmZ ddlmZmZmZ ddl	Z	 e	j                  e      ZddlmZ ddlmZmZmZmZ ddlmZmZmZ dd	lmZ dd
lmZmZmZmZ ddlm Z  ddl!m"c m#Z$ g dZ%da&d Z'dZ( G d de$jR                  e$jT                        Z+ G d de$jX                  e+      Z- G d de+      Z. G d de+      Z/ e$j`                  de ed       ed      d      Z1de1_2        e1xjf                  dz  c_3         G d de      Z4 G d d e-      Z5 G d! d"e5      Z6 e$j`                  d# ejn                  d$%       ed&       ed'      d()      Z8d&e8_2        e8xjf                  dz  c_3         G d* d+e$jr                  e$jR                  e$jT                        Z: G d, d-e$jv                  jx                  e$jz                        Z>y).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_disabledc                  &    t         ddlm a  t         S )Nr   )	des_crypt)r   passlib.hash     Y/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/passlib/handlers/django.py_import_des_cryptr$   &   s    *r"   >abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789c                   N    e Zd ZdZdZdZdZeZe	j                  Zed        Zd Zy)DjangoSaltedHashz2base class providing common code for django hashes)salt	salt_size   Nc                 `    t        j                  || j                  |       \  }} | ||      S )Nhandlerr(   checksum)uh	parse_mc2identclshashr(   chks       r#   from_stringzDjangoSaltedHash.from_stringB   s)    LLsyy#>	cs++r"   c                 l    t        j                  | j                  | j                  | j                        S N)r0   
render_mc2r2   r(   r/   selfs    r#   	to_stringzDjangoSaltedHash.to_stringG   s!    }}TZZDMMBBr"   )__name__
__module____qualname____doc__setting_kwdsdefault_salt_sizemax_salt_size
SALT_CHARS
salt_charsr0   LOWER_HEX_CHARSchecksum_charsclassmethodr7   r=   r!   r"   r#   r'   r'   2   sA    < )L MJ''N, ,Cr"   r'   c                   H    e Zd ZdZej
                  dz   ZdZed        Zd Z	y)DjangoVariableHashzEbase class providing common code for django hashes w/ variable rounds)rounds   c                 d    t        j                  || j                  |       \  }}} | |||      S )Nr,   )rL   r(   r/   )r0   	parse_mc3r2   )r4   r5   rL   r(   r6   s        r#   r7   zDjangoVariableHash.from_stringQ   s.    LLsyy#Fc&tc::r"   c                     t        j                  | j                  | j                  | j                  | j
                        S r9   )r0   
render_mc3r2   rL   r(   r/   r;   s    r#   r=   zDjangoVariableHash.to_stringV   s'    }}TZZdiiOOr"   N)
r>   r?   r@   rA   r'   rB   
min_roundsrI   r7   r=   r!   r"   r#   rK   rK   K   s2    O#00;>LJ; ;Pr"   rK   c                   2    e Zd ZdZd ZdZ ed      ZdZd Z	y)r   a  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.
    r   zsha1$(   c                     t        |t              r|j                  d      }t        t	        | j
                  j                  d      |z         j                               S Nutf-8ascii)
isinstancer   encoder   r   r(   	hexdigestr<   secrets     r#   _calc_checksumz!django_salted_sha1._calc_checksumy   sG    fg&]]7+FT$))"2"27";f"DEOOQRRr"   N
r>   r?   r@   rA   namedjango_namer   r2   checksum_sizer^   r!   r"   r#   r   r   Y   s'    4  DKgJEMSr"   r   c                   2    e Zd ZdZd ZdZ ed      ZdZd Z	y)r   a  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.
    r   zmd5$    c                     t        |t              r|j                  d      }t        t	        | j
                  j                  d      |z         j                               S rV   )rY   r   rZ   r   r   r(   r[   r\   s     r#   r^   z django_salted_md5._calc_checksum   sG    fg&]]7+FS!1!1'!:V!CDNNPQQr"   Nr_   r!   r"   r#   r   r   ~   s'    6 DKfIEMRr"   r   r   zbcrypt$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
    )prefixr2   docr
   )ra   c                   l     e Zd ZdZd ZdZeZ ed      Z	e
d        Ze
 fd       Z fdZ fdZ xZS )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
    bcrypt_sha256zbcrypt_sha256$c                 h    t        j                  |      }|sy|j                  | j                        S NF)r0   to_unicode_for_identify
startswithdjango_prefixr4   r5   s     r#   identifyzdjango_bcrypt_sha256.identify   s-    ))$/s0011r"   c                 H   t        |dd      }|j                  | j                        st        j                  j                  |       |t        | j                        d  }|j                  d      st        j                  j                  |       t        t        | +  |      S )NrX   r5   z$2)r   rn   ro   r0   excInvalidHashErrorlenMalformedHashErrorsuperri   r7   )r4   r5   bhash	__class__s      r#   r7   z django_bcrypt_sha256.from_string   s    $0s001&&))#..S**+,-%&&++C00)3;EBBr"   c                 X    t         t        |          }t        | j                        |z   S r9   )rw   ri   r=   r   ro   )r<   rx   ry   s     r#   r=   zdjango_bcrypt_sha256.to_string   s)    *D;=T//0588r"   c                     t        |t              r|j                  d      }t        | j	                  |      j                               }t        t        | #  |      S )NrW   )	rY   r   rZ   r   _digestdigestrw   ri   r^   )r<   r]   ry   s     r#   r^   z#django_bcrypt_sha256._calc_checksum   sJ    fg&]]7+Ff-4467)4?GGr"   )r>   r?   r@   rA   r`   ra   r   r|   r   ro   rI   rq   r7   r=   r^   __classcell__)ry   s   @r#   ri   ri      s_    	 "D!KG &'M2 2 C C9H Hr"   ri   c                   n    e Zd ZdZd ZdZ ed      ZdZdZ	e
j                  ZdZej                  ZdZd Zy	)
r   a  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
    r   zpbkdf2_sha256$rM   l    ,   r   c                     t        | j                  || j                  | j                        }t	        |      j                         j                  d      S )NrX   )r   r|   r(   rL   r   rstripdecode)r<   r]   r5   s      r#   r^   z#django_pbkdf2_sha256._calc_checksum#  s<    4<<DKKH%%'..w77r"   N)r>   r?   r@   rA   r`   ra   r   r2   min_salt_size
max_roundsr0   PADDED_BASE64_CHARSrH   rb   r   default_roundsr|   r^   r!   r"   r#   r   r      sN    "F "D!KEMJ++NM"11NG8r"   r   c                   H    e Zd ZdZd ZdZ ed      ZdZe	j                  Z
dZy)r   a  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$   r   N)r>   r?   r@   rA   r`   ra   r   r2   rb   r   r   r|   r!   r"   r#   r   r   (  s3    "F  DKnEM //NGr"   r   r   I)typer	   zargon2$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
    )r`   wrappedrf   r2   rg   c                   x    e Zd ZdZd ZdZdZ ed      Ze	j                  xZZdZdxZZdZdZed	        Zd
 Zd Zy)r   a  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.
    crypt)r(   r)   truncate_errorzcrypt$         Tc                     t        j                  || j                  |       \  }}|r8|s|d d }n+|d d |d d k7  r t         j                  j	                  | d      |dd  } | ||      S )Nr,   r   z0first two digits of salt and checksum must matchr.   )r0   r1   r2   rs   rv   r3   s       r#   r7   zdjango_des_crypt.from_string  s}    LLsyy#>	c 2AwbqS!W$ ff//FH H ab'Cs++r"   c                     | j                   }|d d | j                  z   }| j                  r!t        j                  | j
                  ||      S t        j                  | j
                  d|      S )Nr    )r(   r/   use_duplicate_saltr0   r:   r2   )r<   r(   r6   s      r#   r=   zdjango_des_crypt.to_string  sX    yy2Ah&""==T377 ==R55r"   c                     t         
t                | j                  r| j                  |       t        | j                  d d       j                  |      S )Nr   )r(   )r   r$   use_defaults_check_truncate_policyr(   r^   r\   s     r#   r^   zdjango_des_crypt._calc_checksum  sG     ''/diim,;;FCCr"   N)r>   r?   r@   rA   r`   ra   rB   r   r2   r0   HASH64_CHARSrH   rF   rb   r   rC   truncate_sizer   rI   r7   r=   r^   r!   r"   r#   r   r   t  si    : DK:LhKE"$//1NZM())M%M , ,$6	Dr"   r   c                   N    e Zd ZdZd Z ed      ZdZed        Z	d Z
ed        Zy)r   aF  This 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.
    !rT   c                 b    t        j                  |      }|j                  | j                        S r9   )r0   rm   rn   _hash_prefixrp   s     r#   rq   zdjango_disabled.identify  s'    ))$/s//00r"   c                 F    t        t        t        d d | j                        S )N)r   r   r   suffix_lengthr\   s     r#   r^   zdjango_disabled._calc_checksum  s    #|CR0$2D2DEEr"   c                     t        j                  |       | j                  |      st         j                  j	                  |       yrl   )r0   validate_secretrq   rs   rt   )r4   r]   r5   s      r#   verifyzdjango_disabled.verify  s4    
6"||D!&&))#..r"   N)r>   r?   r@   rA   r`   r   r   r   rI   rq   r^   r   r!   r"   r#   r   r     sJ    , DS6LM 1 1F  r"   r   )?rA   base64r   binasciir   hashlibr   r   r   logging	getLoggerr>   logpasslib.handlers.bcryptr   r    r	   r
   r   r   passlib.utilsr   r   r   passlib.utils.binaryr   passlib.utils.compatr   r   r   r   passlib.crypto.digestr   passlib.utils.handlersutilshandlersr0   __all__r   r$   rE   HasSaltGenericHandlerr'   	HasRoundsrK   r   r   PrefixWrapperr   ra   _using_clone_attrsri   r   r   usingr   TruncateMixinr   ifcDisabledHashStaticHandlerr   r!   r"   r#   <module>r      s   ;
   % % 'g''1 4 C C 5 5 - I I - # #	  	 N

Crzz2#4#4 C2P'7 P#S) #SJ$R( $RT !  &Y<q|			" %      $4 4  /H? /Hj18- 18f)- )d !  	FLLc"X;

		( %      $4 4  
\Dr''R5F5F \D|*bff))2+;+; *r"   