Current File : //usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyo
�
�
5Xc@s(dZddlmZmZddlmZddlZddlZeje	�Z
ddlmZddl
mZddlmZmZmZddljjZdd	gZd
�ZdZed�Zd�Zd
�Zdejejejfd��YZ d	ejejejfd��YZ!dS(s�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/
i����(thexlifyt	unhexlify(tsha1N(twarn(tconsteq(t
bascii_to_strtunicodetut	mssql2000t	mssql2005cCst|jd�|�j�S(Ns	utf-16-le(Rtencodetdigest(tsecrettsalt((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyt
_raw_mssql9st0x0100cCs�t|t�r7t|�|kr�|jt�r�tSnLt|t�rnt|�|kr�|jt�r�tSntj	j
|d��tS(s#common identify for mssql 2000/2005thash(t
isinstanceRtlent
startswithtUIDENTtTruetbytestBIDENTtuhtexctExpectedStringErrortFalse(Rtcsizetbsize((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyt_ident_mssqlBs!!cCs�t|t�ret|�|kr�|jt�r�yt|djd��SWqbtk
r^qbXq�nqt|t�r�t|�|kr�|jt	�r�yt|d�SWq�tk
r�q�Xq�nt
jj|d��t
jj
|��dS(sAcommon parser for mssql 2000/2005; returns 4 byte salt + checksumisutf-8RN(RRRRRRR
t	TypeErrorRRRRRtInvalidHashError(RRRthandler((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyt_parse_mssqlPs!

!

cBsieZdZdZd
ZdZdZZed��Z	ed��Z
d�Zd�Zed	��Z
RS(s*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.
    RR
i(icCst|dd�S(Ni^i.(R(tclsR((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pytidentify�scCs0t|dd|�}|d|d d|d�S(Ni^i.R
itchecksum(R"(R#Rtdata((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pytfrom_string�scCs*|j|j}dtt|�j��S(NR(R
R%RRtupper(tselftraw((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyt	to_string�scCsJt|t�r!|jd�}n|j}t||�t|j�|�S(Nsutf-8(RRtdecodeR
RR((R)RR
((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyt_calc_checksum�s	cCs�tj|�|j|�}|j}|dkrFtjj|��nt|t�rg|j	d�}nt
|j�|j�}t
||d�S(Nsutf-8i(Rtvalidate_secretR'R%tNoneRtMissingDigestErrorRRR,RR(R
R(R#RRR)tchktresult((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pytverify�s
	(ssalt(t__name__t
__module__t__doc__tnametsetting_kwdst
checksum_sizet
min_salt_sizet
max_salt_sizetclassmethodR$R'R+R-R3(((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyRfs

		cBsZeZdZdZd	ZdZdZZed��Z	ed��Z
d�Zd�ZRS(
s*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	R
iicCst|dd�S(Ni6i(R(R#R((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyR$�scCs0t|dd|�}|d|d d|d�S(Ni6iR
iR%(R"(R#RR&((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyR'�scCs*|j|j}dtt|��j�S(NR(R
R%RRR((R)R*((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyR+�scCs1t|t�r!|jd�}nt||j�S(Nsutf-8(RRR,RR
(R)R((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyR-�s(ssalt(
R4R5R6R7R8R9R:R;R<R$R'R+R-(((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyR	�s
	("R6tbinasciiRRthashlibRtretloggingt	getLoggerR4tlogtwarningsRt
passlib.utilsRtpasslib.utils.compatRRRtpasslib.utils.handlerstutilsthandlersRt__all__RRRRR"t
HasRawSalttHasRawChecksumtGenericHandlerRR	(((s:/usr/lib/python2.7/site-packages/passlib/handlers/mssql.pyt<module>!s$				%M