ó ö 5Xc@s§dZddlmZddlZejeƒZddlmZddl m Z m Z m 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 dZ dZ 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_identRt decode_int6tencodetNone(tclsthashRtdataRRtchk((s;/usr/lib/python2.7/site-packages/passlib/handlers/phpass.pyt from_string`s#cCsPtdƒ|jtj|jƒjdƒ|j|jp?tdƒf}t|ƒS(Ns%s%s%s%sR t( RRRt encode_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(Rtsecrett real_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_roundst rounds_costRt default_identt ident_valuest ident_aliasest classmethodRRR#(((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.pyts