Current File : //usr/lib/python2.7/site-packages/passlib/handlers/phpass.pyc
�
�
5Xc@s�dZddlmZddlZeje�ZddlmZddl	m
Z
mZmZddl
jjZdgZdejejejejfd��YZdS(s�passlib.handlers.phpass - PHPass Portable Crypt

phppass located - http://www.openwall.com/phpass/
algorithm described - http://www.openwall.com/articles/PHP-Users-Passwords

phpass context - blowfish, bsdi_crypt, phpass
i����(tmd5N(th64(tut
uascii_to_strtunicodetphpasscBs�eZdZdZdZejZdZZ	ejZ
dZdZdZ
d	Zed
�Zed
�ed�fZied
�ed�6ed�ed
�6Zed��Zd�Zd�ZRS(s�This class implements the PHPass Portable Hash, and follows the :ref:`password-hash-api`.

    It supports a fixed-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, one will be autogenerated (this is recommended).
        If specified, it must be 8 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 19, must be between 7 and 30, inclusive.
        This value is logarithmic, the actual number of iterations used will be :samp:`2**{rounds}`.

    :type ident: str
    :param ident:
        phpBB3 uses ``H`` instead of ``P`` for its identifier,
        this may be set to ``H`` in order to generate phpBB3 compatible hashes.
        it defaults to ``P``.

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

        .. versionadded:: 1.6
    Rtsalttroundstidentiiiitlog2s$P$s$H$tPtHc
Cso|j|�\}}|d|dd!|d}}}|d|dtj|jd��d|d|pkd�S(	Niii	RRtasciiRtchecksum(t_parse_identRtdecode_int6tencodetNone(tclsthashRtdataRRtchk((s;/usr/lib/python2.7/site-packages/passlib/handlers/phpass.pytfrom_string`s#cCsPtd�|jtj|j�jd�|j|jp?td�f}t|�S(Ns%s%s%s%sRt(	RRRtencode_int6RtdecodeRR
R(tselfR((s;/usr/lib/python2.7/site-packages/passlib/handlers/phpass.pyt	to_stringks
cCs�t|t�r!|jd�}nd|j>}t|jjd�|�j�}d}x0||kr�t||�j�}|d7}qYWtj|�j	d�S(Nsutf-8iRi(
t
isinstanceRRRRRtdigestRtencode_bytesR(Rtsecrettreal_roundstresulttr((s;/usr/lib/python2.7/site-packages/passlib/handlers/phpass.pyt_calc_checksumus
"(ssaltsroundssident(t__name__t
__module__t__doc__tnametsetting_kwdstuhtHASH64_CHARStchecksum_charst
min_salt_sizet
max_salt_sizet
salt_charstdefault_roundst
min_roundst
max_roundstrounds_costRt
default_identtident_valuest
ident_aliasestclassmethodRRR#(((s;/usr/lib/python2.7/site-packages/passlib/handlers/phpass.pyRs "	
	,	
(R&thashlibRtloggingt	getLoggerR$tlogtpasslib.utils.binaryRtpasslib.utils.compatRRRtpasslib.utils.handlerstutilsthandlersR)t__all__t
HasManyIdentst	HasRoundstHasSalttGenericHandlerR(((s;/usr/lib/python2.7/site-packages/passlib/handlers/phpass.pyt<module>s