Ë
    àU.j"!  ã                   óp  — d Z ddlmZmZ ddlmZ ddlZddlZ ej                  e	«      Z
ddlmZ ddlmZ ddlmZmZmZ ddlmc mZ dd	gZd
„ ZdZ ed«      Zd„ Zd„ Z G d„ dej:                  ej<                  ej>                  «      Z  G d„ d	ej:                  ej<                  ej>                  «      Z!y)aÈ  passlib.handlers.mssql - MS-SQL Password Hash

Notes
=====
MS-SQL has used a number of hash algs over the years,
most of which were exposed through the undocumented
'pwdencrypt' and 'pwdcompare' sql functions.

Known formats
-------------
6.5
    snefru hash, ascii encoded password
    no examples found

7.0
    snefru hash, unicode (what encoding?)
    saw ref that these blobs were 16 bytes in size
    no examples found

2000
    byte string using displayed as 0x hex, using 0x0100 prefix.
    contains hashes of password and upper-case password.

2007
    same as 2000, but without the upper-case hash.

refs
----------
https://blogs.msdn.com/b/lcris/archive/2007/04/30/sql-server-2005-about-login-password-hashes.aspx?Redirected=true
http://us.generation-nt.com/securing-passwords-hash-help-35429432.html
http://forum.md5decrypter.co.uk/topic230-mysql-and-mssql-get-password-hashes.aspx
http://www.theregister.co.uk/2002/07/08/cracking_ms_sql_server_passwords/
é    )ÚhexlifyÚ	unhexlify)Úsha1N)Úwarn)Úconsteq)Úbascii_to_strÚunicodeÚuÚ	mssql2000Ú	mssql2005c                 ó    — t        | t        «      sJ ‚t        |t        «      sJ ‚t        | j	                  d«      |z   «      j                  «       S )Nz	utf-16-le)Ú
isinstancer	   Úbytesr   ÚencodeÚdigest)ÚsecretÚsalts     úXC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\passlib/handlers/mssql.pyÚ
_raw_mssqlr   9   sD   € Ü�fœgÔ&Ð&Ð&Ü�dœEÔ"Ð"Ð"Ü�—‘˜kÓ*¨TÑ1Ó2×9Ñ9Ó;Ð;ó    s   0x0100Ú0x0100c                 ó  — t        | t        «      r%t        | «      |k(  r| j                  t        «      ryyt        | t
        «      r%t        | «      |k(  r| j                  t        «      ryyt        j                  j                  | d«      ‚)z#common identify for mssql 2000/2005TÚhashF)
r   r	   ÚlenÚ
startswithÚUIDENTr   ÚBIDENTÚuhÚexcÚExpectedStringError)r   ÚcsizeÚbsizes      r   Ú_ident_mssqlr#   B   so   € ä�$œÔ Üˆt‹9˜Ò $§/¡/´&Ô"9Øð ô 
�Dœ%Ô	 Üˆt‹9˜Ò $§/¡/´&Ô"9Øð
 ô �f‰f×(Ñ(¨¨vÓ6Ð6r   c                 ó  — t        | t        «      rAt        | «      |k(  r§| j                  t        «      r’	 t        | dd j                  d«      «      S t        | t        «      rDt        | t        «      sJ ‚t        | «      |k(  rD| j                  t        «      r/	 t        | dd «      S t        j                  j                  | d«      ‚t        j                  j                  |«      ‚# t        $ r Y Œ*w xY w# t        $ r Y Œ9w xY w)zAcommon parser for mssql 2000/2005; returns 4 byte salt + checksumé   Núutf-8r   )r   r	   r   r   r   r   r   Ú	TypeErrorr   r   r   r   r    ÚInvalidHashError)r   r!   r"   Úhandlers       r   Ú_parse_mssqlr*   P   sà   € ä�$œÔ Üˆt‹9˜Ò $§/¡/´&Ô"9ðÜ   a b §¡°Ó!9Ó:Ð:ô 
�Dœ%Ô	 ä˜$¤Ô&Ð&Ð&Üˆt‹9˜Ò $§/¡/´&Ô"9ðÜ   a b Ó*Ð*ô �f‰f×(Ñ(¨¨vÓ6Ð6Ü
�&‰&×
!Ñ
! 'Ó
*Ð*øô ò Ùðûô ò Ùðús#   µC% ÂC4 Ã%	C1Ã0C1Ã4	D Ã?D c                   ó`   — e Zd ZdZd ZdZdZdxZZe	d„ «       Z
e	d„ «       Zd„ Zd„ Ze	d	„ «       Zy
)r   a*  This class implements the password hash used by MS-SQL 2000, and follows the :ref:`password-hash-api`.

    It supports a fixed-length salt.

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

    :type salt: bytes
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 4 bytes in length.

    :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
        ``salt`` strings that are too long.
    ©r   é(   é   c                 ó   — t        |dd«      S )Né^   é.   ©r#   ©Úclsr   s     r   Úidentifyzmssql2000.identifyŽ   ó   € ä˜D " bÓ)Ð)r   c                 ó>   — t        |dd| «      } | |d d |dd  ¬«      S )Nr0   r1   r.   ©r   Úchecksum©r*   ©r4   r   Údatas      r   Úfrom_stringzmssql2000.from_string’   ó+   € ä˜D " b¨#Ó.ˆÙ˜˜R˜a˜¨4°°¨8Ô4Ð4r   c                 ó~   — | j                   | j                  z   }dt        t        |«      j	                  «       «      z   S ©Nr   ©r   r9   r   r   Úupper©ÚselfÚraws     r   Ú	to_stringzmssql2000.to_string—   s1   € Ø�i‰i˜$Ÿ-™-Ñ'ˆàœ-¬°«×(:Ñ(:Ó(<Ó=Ñ=Ð=r   c                 óª   — t        |t        «      r|j                  d«      }| j                  }t	        ||«      t	        |j                  «       |«      z   S ©Nr&   )r   r   Údecoder   r   rB   )rD   r   r   s      r   Ú_calc_checksumzmssql2000._calc_checksumœ   sB   € Ü�fœeÔ$Ø—]‘] 7Ó+ˆFØ�y‰yˆÜ˜& $Ó'¬*°V·\±\³^ÀTÓ*JÑJÐJr   c                 óP  — t        j                  |«       | j                  |«      }|j                  }|€t         j                  j                  | «      ‚t        |t        «      r|j                  d«      }t        |j                  «       |j                  «      }t        ||dd  «      S )Nr&   é   )r   Úvalidate_secretr=   r9   r   ÚMissingDigestErrorr   r   rI   r   rB   r   r   )r4   r   r   rD   ÚchkÚresults         r   Úverifyzmssql2000.verify¢   s„   € ô 	×Ñ˜6Ô"Ø�‰˜tÓ$ˆØ�m‰mˆØˆ;Ü—&‘&×+Ñ+¨CÓ0Ð0Ü�fœeÔ$Ø—]‘] 7Ó+ˆFÜ˜FŸL™L›N¨D¯I©IÓ6ˆÜ�v˜s 2 3˜xÓ(Ð(r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚsetting_kwdsÚchecksum_sizeÚmin_salt_sizeÚmax_salt_sizeÚclassmethodr5   r=   rF   rJ   rQ   © r   r   r   r   f   si   „ ñð. €DØ€LØ€MØ$%Ð%€M�Mð ñ*ó ð*ð ñ5ó ð5ò>ò
Kð ñ)ó ñ)r   c                   óP   — e Zd ZdZd ZdZdZdxZZe	d„ «       Z
e	d„ «       Zd„ Zd„ Zy	)
r   a*  This class implements the password hash used by MS-SQL 2005, and follows the :ref:`password-hash-api`.

    It supports a fixed-length salt.

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

    :type salt: bytes
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 4 bytes in length.

    :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
        ``salt`` strings that are too long.
    r,   rL   r.   c                 ó   — t        |dd«      S )Né6   é   r2   r3   s     r   r5   zmssql2005.identifyÛ   r6   r   c                 ó>   — t        |dd| «      } | |d d |dd  ¬«      S )Nr_   r`   r.   r8   r:   r;   s      r   r=   zmssql2005.from_stringß   r>   r   c                 ó~   — | j                   | j                  z   }dt        t        |«      «      j	                  «       z   S r@   rA   rC   s     r   rF   zmssql2005.to_stringä   s1   € Ø�i‰i˜$Ÿ-™-Ñ'ˆàœ-¬°«Ó5×;Ñ;Ó=Ñ=Ð=r   c                 óp   — t        |t        «      r|j                  d«      }t        || j                  «      S rH   )r   r   rI   r   r   )rD   r   s     r   rJ   zmssql2005._calc_checksumé   s+   € Ü�fœeÔ$Ø—]‘] 7Ó+ˆFÜ˜& $§)¡)Ó,Ð,r   N)rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r5   r=   rF   rJ   r\   r   r   r   r   ³   sT   „ ñð. €DØ€Là€MØ$%Ð%€M�Mð ñ*ó ð*ð ñ5ó ð5ò>ó
-r   )"rU   Úbinasciir   r   Úhashlibr   ÚreÚloggingÚ	getLoggerrR   ÚlogÚwarningsr   Úpasslib.utilsr   Úpasslib.utils.compatr   r	   r
   Úpasslib.utils.handlersÚutilsÚhandlersr   Ú__all__r   r   r   r#   r*   Ú
HasRawSaltÚHasRawChecksumÚGenericHandlerr   r   r\   r   r   Ú<module>rt      s°   ðñ ÷J (Ý Û 	Û Ð'�g×'Ñ'¨Ó1�Ý õ "ß :Ñ :ß #Ð #ð Øð€ò<ð
 
€á	
ˆ8‹€òò+ô,H)�—‘˜r×0Ñ0°"×2CÑ2Cô H)ôZ9-�—‘˜r×0Ñ0°"×2CÑ2Cõ 9-r   