Current File : //usr/lib/python2.7/site-packages/passlib/handlers/django.pyo
�
�
5Xc	@s�dZddlmZddlmZddlmZmZmZddl	Z	e	j
e�Zddl
mZddlmZmZmZmZddlmZmZmZdd	lmZdd
lmZmZmZmZddlm Z ddl!j"j#Z$dd
ddddddgZ%da'd�Z(dZ)de$j*e$j+fd��YZ,de$j-e,fd��YZ.de,fd��YZ/d
e,fd��YZ0e$j1deded�ded�dd �Z2d!e2_3e2j4d,7_4d#efd$��YZ5de.fd%��YZ6de6fd&��YZ7e$j1deded'�ded(�dd)�Z8d'e8_3e8j4d-7_4de$j9e$j*e$j+fd*��YZ:de$j;j<e$j=fd+��YZ>dS(.s5passlib.handlers.django- Django password hash supporti����(t	b64encode(thexlify(tmd5tsha1tsha256N(t_wrapped_bcrypt(targon2tbcrypttpbkdf2_sha1t
pbkdf2_sha256(t
to_unicodetrngt
getrandstr(tBASE64_CHARS(t
str_to_uasciit
uascii_to_strtunicodetu(tpbkdf2_hmactdjango_salted_sha1tdjango_salted_md5t
django_bcrypttdjango_pbkdf2_sha1tdjango_pbkdf2_sha256t
django_argon2tdjango_des_crypttdjango_disabledcCs#tdkrddlmantS(Ni����(t	des_crypt(RtNonetpasslib.hash(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyt_import_des_crypt&st>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789tDjangoSaltedHashcBsGeZdZdZdZdZeZe	j
Zed��Z
d�ZRS(s2base class providing common code for django hashestsaltt	salt_sizeicCs4tj||jd|�\}}|d|d|�S(NthandlerR!tchecksum(tuht	parse_mc2tident(tclsthashR!tchk((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pytfrom_stringBs!cCstj|j|j|j�S(N(R%t
render_mc2R'R!R$(tself((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyt	to_stringGs(ssaltR"N(t__name__t
__module__t__doc__tsetting_kwdstdefault_salt_sizeRt
max_salt_sizet
SALT_CHARSt
salt_charsR%tLOWER_HEX_CHARStchecksum_charstclassmethodR+R.(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR 2s	tDjangoVariableHashcBs9eZdZejdZdZed��Zd�ZRS(sEbase class providing common code for django hashes w/ variable roundstroundsicCs=tj||jd|�\}}}|d|d|d|�S(NR#R;R!R$(R%t	parse_mc3R'(R(R)R;R!R*((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR+Qs$cCs"tj|j|j|j|j�S(N(R%t
render_mc3R'R;R!R$(R-((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR.Vs(srounds(	R/R0R1R R2t
min_roundsR9R+R.(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR:Ks

cBs5eZdZdZdZed�ZdZd�ZRS(s�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.
    RRssha1$i(cCsGt|t�r!|jd�}ntt|jjd�|�j��S(Nsutf-8tascii(t
isinstanceRtencodeRRR!t	hexdigest(R-tsecret((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyt_calc_checksumys(	R/R0R1tnametdjango_nameRR't
checksum_sizeRD(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyRYscBs5eZdZdZdZed�ZdZd�ZRS(s�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.
    RRsmd5$i cCsGt|t�r!|jd�}ntt|jjd�|�j��S(Nsutf-8R?(R@RRARRR!RB(R-RC((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyRD�s(	R/R0R1RERFRR'RGRD(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR~stprefixsbcrypt$R'tdocs�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
    RRFtdjango_bcrypt_sha256cBs\eZdZdZdZeZed�Ze	d��Z
e	d��Zd�Zd�Z
RS(s�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
    RJt
bcrypt_sha256sbcrypt_sha256$cCs)tj|�}|stS|j|j�S(N(R%tto_unicode_for_identifytFalset
startswitht
django_prefix(R(R)((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pytidentify�scCs�t|dd�}|j|j�s9tjj|��n|t|j�}|jd�sptjj|��ntt	|�j
|�S(NR?R)s$2(R
RNROR%texctInvalidHashErrortlentMalformedHashErrortsuperRJR+(R(R)tbhash((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR+�scCs&tt|�j�}t|j�|S(N(RURJR.RRO(R-RV((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR.�scCsRt|t�r!|jd�}nt|j|�j��}tt|�j|�S(Nsutf-8(	R@RRARt_digesttdigestRURJRD(R-RC((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyRD�s(R/R0R1RERFRRWRROR9RPR+R.RD(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyRJ�s

	cBsYeZdZdZdZed�ZdZdZe	j
ZdZe
jZdZd�ZRS(	s�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
    RR	spbkdf2_sha256$iI����i,RcCs7t|j||j|j�}t|�j�jd�S(NR?(RRWR!R;Rtrstriptdecode(R-RCR)((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyRD#s(R/R0R1RERFRR't
min_salt_sizet
max_roundsR%tPADDED_BASE64_CHARSR8RGR	tdefault_roundsRWRD(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR�s#		cBs;eZdZdZdZed�ZdZej	Z	dZ
RS(s�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
    RRspbkdf2_sha1$iR(R/R0R1RERFRR'RGRR^RW(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR(s#	Rsargon2$argon2i$s�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
    cBsveZdZdZdZd
Zed�Zej	Z
ZdZdZ
Zd	ZeZed
��Zd�Zd�ZRS(s�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.
    RtcryptR!R"ttruncate_errorscrypt$iiicCs�tj||jd|�\}}|rs|s:|d }n,|d |d krftjj|d��n|d}n|d|d|�S(NR#is0first two digits of salt and checksum must matchR!R$(R%R&R'RQRT(R(R)R!R*((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR+�s!

cCsS|j}|d |j}|jr9tj|j||�Stj|jd|�SdS(Nit(R!R$tuse_duplicate_saltR%R,R'(R-R!R*((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR.�s
		cCsLtdkrt�n|jr/|j|�ntd|jd �j|�S(NR!i(RRRtuse_defaultst_check_truncate_policyR!RD(R-RC((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyRD�s

	(ssalts	salt_sizeR`(R/R0R1RERFR2RR'R%tHASH64_CHARSR8R6RGR[R3t
truncate_sizetTrueRbR9R+R.RD(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyRns

	
cBsMeZdZdZed�ZdZed��Zd�Z	ed��Z
RS(sFThis 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!i(cCstj|�}|j|j�S(N(R%RLRNt_hash_prefix(R(R)((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyRP�scCstttd |j�S(Ni����(RRR
t
suffix_length(R-RC((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyRD�scCs5tj|�|j|�s1tjj|��ntS(N(R%tvalidate_secretRPRQRRRM(R(RCR)((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pytverify�s
(R/R0R1RERRiRjR9RPRDRl(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyR�s	(sdjango_name(sdjango_name(?R1tbase64RtbinasciiRthashlibRRRtloggingt	getLoggerR/tlogtpasslib.handlers.bcryptRRRRRR	t
passlib.utilsR
RRtpasslib.utils.binaryR
tpasslib.utils.compatRRRRtpasslib.crypto.digestRtpasslib.utils.handlerstutilsthandlersR%t__all__RRRR5tHasSalttGenericHandlerR t	HasRoundsR:RRt
PrefixWrapperRRFt_using_clone_attrsRJRRRt
TruncateMixinRtifctDisabledHasht
StaticHandlerR(((s;/usr/lib/python2.7/site-packages/passlib/handlers/django.pyt<module>sT""		%*		53/		%^