a fŸWcE¶ã@sdZddlmZddlZe e¡ZddlZddlm Z ddl m Z m Z ddl mZddlmZddlmZdd lmZmZmZdd lmZdd lmZmZmZmZd d gZeƒZ dZ!dZ"dZ#dZ$dZ%Gdd„deƒZ&e'ƒZ(dd„Z)e)ƒZ*dd„Z+e+ƒZ,Gdd „d e&ƒZ-Gdd „d e&ƒZ.dS)z(passlib.apache - apache password supporté)Úwith_statementN)Úwarn)ÚexcÚregistry)Ú CryptContext)ÚExpectedStringError)Úhtdigest)Ú render_bytesÚto_bytesÚis_ascii_codec)Údeprecated_method)Ú join_bytesÚunicodeÚBytesIOÚPY3Ú HtpasswdFileÚ HtdigestFileó:ó#s: ÚskippedÚrecordc@seZdZdZdZdZdZdZdZdZ dZ e dd„ƒZ e dd„ƒZ ddddd efd d „Zd d „Zedd„ƒZejdd„ƒZedd„ƒZdd„Zd2dd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd3d!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Z d+d,„Z!d4d.d/„Z"d0d1„Z#dS)5Ú _CommonFilez0common framework for HtpasswdFile & HtdigestFileNFcKs,d|vrtdƒ‚|fi|¤Ž}| |¡|S)zöcreate new object from raw string. :type data: unicode or bytes :arg data: database to load, as single string. :param \*\*kwds: all other keywords are the same as in the class constructor Úpathz$'path' not accepted by from_string())Ú TypeErrorÚ load_string)ÚclsÚdataÚkwdsÚself©rú2/usr/lib/python3.9/site-packages/passlib/apache.pyÚ from_stringKs  z_CommonFile.from_stringcKs|fi|¤Ž}| |¡|S)zûcreate new object from file, without binding object to file. :type path: str :arg path: local filepath to load from :param \*\*kwds: all other keywords are the same as in the class constructor )Úload)rrrrrrr Ú from_path\s  z_CommonFile.from_pathTúutf-8cCs‚|stdtdd�d}d}nt|ƒs,tdƒ‚||_||_||_||_d|_|s`tdtdd�d }|rr|sr|  ¡n i|_ g|_ dS) Nz„``encoding=None`` is deprecated as of Passlib 1.6, and will cause a ValueError in Passlib 1.8, use ``return_unicode=False`` instead.é©Ú stacklevelr$Fz'encoding must be 7-bit ascii compatiblerzp``autoload=False`` is deprecated as of Passlib 1.6, and will be removed in Passlib 1.8, use ``new=True`` insteadT) rÚDeprecationWarningr Ú ValueErrorÚencodingÚreturn_unicodeÚautosaveÚ_pathÚ_mtimer"Ú_recordsÚ_source)rrÚnewZautoloadr,r*r+rrr Ú__init__ns,ýþ z_CommonFile.__init__cCsTd}|jr|d7}|jr&|d|j7}|jdkr>|d|j7}d|jjt|ƒ|fS)NÚz autosave=Truez path=%rr$z encoding=%rz <%s 0x%0x%s>)r,r-r*Ú __class__Ú__name__Úid)rÚtailrrr Ú__repr__‘s z_CommonFile.__repr__cCs|jS©N)r-©rrrr r�sz_CommonFile.pathcCs||jkrd|_||_dS)Nr)r-r.©rÚvaluerrr r¡s cCs|jS)z7modify time when last loaded (if bound to a local file))r.r:rrr Úmtime§sz_CommonFile.mtimecCs<|jstd|ƒ‚|jr0|jtj |j¡kr0dS| ¡dS)zBReload from ``self.path`` only if file has changed since last loadz%r is not bound to a local fileFT)r-Ú RuntimeErrorr.ÚosrÚgetmtimer"r:rrr Úload_if_changed¯s  z_CommonFile.load_if_changedcCsÎ|durDt|dƒ� }d|_| |¡WdƒqÊ1s80Yn†|sltdt|jjd�tdd�| ¡S|j rºt|j dƒ�*}t j   |j ¡|_| |¡WdƒqÊ1s®0Ynt d|jjƒ‚d S) aôLoad state from local file. If no path is specified, attempts to load from ``self.path``. :type path: str :arg path: local file to load from :type force: bool :param force: if ``force=False``, only load from ``self.path`` if file has changed since last load. .. deprecated:: 1.6 This keyword will be removed in Passlib 1.8; Applications should use :meth:`load_if_changed` instead. NÚrbrz†%(name)s.load(force=False) is deprecated as of Passlib 1.6,and will be removed in Passlib 1.8; use %(name)s.load_if_changed() instead.)Únamer%r&z2%s().path is not set, an explicit path is requiredT)Úopenr.Ú _load_linesrÚdictr4r5r(rAr-r?rr@r>)rrÚforceÚfhrrr r"¸s& * ýü*ÿz_CommonFile.loadcCs&t||jdƒ}d|_| t|ƒ¡dS)z@Load state from unicode or bytes string, replacing current staterrN)r r*r.rEr)rrrrr rÜsz_CommonFile.load_stringc CsÈ|j}i}g}d}t|ƒD]†\}}| ¡}|r8| t¡rB||7}q|||dƒ\} } | |vrtt d| ¡||7}q|rŠ| t|f¡d}| || <| t | f¡q|  ¡r¸| t|f¡||_ ||_ dS)zload from sequence of listsóéz1username occurs multiple times in source file: %rN) Ú _parse_recordÚ enumerateÚlstripÚ startswithÚ_BHASHÚlogZwarningÚappendÚ_SKIPPEDÚ_RECORDÚrstripr/r0) rÚlinesÚparseÚrecordsÚsourcerÚidxÚlineÚtmpÚkeyr<rrr rEâs.z_CommonFile._load_linescCs tdƒ‚dS)z)parse line of file into (key, value) pairú!should be implemented in subclassN©ÚNotImplementedError)rrÚlinenorrr rK sz_CommonFile._parse_recordcCs.|j}||v}|||<|s*|j t|f¡|S)z› helper for setting record which takes care of inserting source line if needed; :returns: bool if key already present )r/r0rQrS)rr\r<rWÚexistingrrr Ú _set_records z_CommonFile._set_recordcCs|jr|jr| ¡dS)z0subclass helper to call save() after any changesN)r,r-Úsaver:rrr Ú _autosave!s z_CommonFile._autosavecCsz|durBt|dƒ�}| | ¡¡Wdƒqv1s60Yn4|jrf| |j¡tj |j¡|_nt d|j j ƒ‚dS)zhSave current state to file. If no path is specified, attempts to save to ``self.path``. NÚwbz%%s().path is not set, cannot autosave) rDÚ writelinesÚ _iter_linesr-rcr?rr@r.r>r4r5)rrrHrrr rc&s . ÿz_CommonFile.savecCs t| ¡ƒS)z)Export current state as a string of bytes)r rgr:rrr Ú to_string4sz_CommonFile.to_stringccsv|j}t|ƒ}|jD]J\}}|tkr,|Vq|tks8J‚||vrBq| |||¡V| |¡q|rrJd|fƒ‚dS)z#iterator yielding lines of databasez'failed to write all records: missing=%rN)r/Úsetr0rRrSÚ_render_recordÚremove)rrWÚpendingÚactionZcontentrrr rg@s  z_CommonFile._iter_linescCs tdƒ‚dS)z,given key/value pair, encode as line of filer]Nr^)rr\r<rrr rj[sz_CommonFile._render_recordcCs | |d¡S)z)user-specific wrapper for _encode_field()Úuser©Ú _encode_field©rrnrrr Ú _encode_userbsz_CommonFile._encode_usercCs | |d¡S)z*realm-specific wrapper for _encode_field()Úrealmro©rrsrrr Ú _encode_realmfsz_CommonFile._encode_realmÚfieldcCsnt|tƒr| |j¡}nt|tƒs,t||ƒ‚t|ƒdkrHtd||fƒ‚tdd„|Dƒƒrjtd||fƒ‚|S)a+convert field to internal representation. internal representation is always bytes. byte strings are left as-is, unicode strings encoding using file's default encoding (or ``utf-8`` if no encoding has been specified). :raises UnicodeEncodeError: if unicode value cannot be encoded using default encoding. :raises ValueError: if resulting byte string contains a forbidden character, or is too long (>255 bytes). :returns: encoded identifer as bytes éÿz%%s must be at most 255 characters: %rcss|]}|tvVqdSr9)Ú_INVALID_FIELD_CHARS)Ú.0Úcrrr Ú ‚rIz,_CommonFile._encode_field..z"%s contains invalid characters: %r) Ú isinstancerÚencoder*ÚbytesrÚlenr)Úany)rr<Zparamrrr rpjs    ÿÿz_CommonFile._encode_fieldcCs,t|tƒsJdƒ‚|jr$| |j¡S|SdS)aWdecode field from internal representation to format returns by users() method, etc. :raises UnicodeDecodeError: if unicode value cannot be decoded using default encoding. (usually indicates wrong encoding set for file). :returns: field as unicode or bytes, as appropriate. zexpected value to be bytesN)r|r~r+Údecoder*r;rrr Ú _decode_field‡s  z_CommonFile._decode_field)NT)N)rv)$r5Ú __module__Ú __qualname__Ú__doc__r*r+r-r.r,r/r0Ú classmethodr!r#rr2r8ÚpropertyrÚsetterr=rAr"rrErKrbrdrcrhrgrjrrrurpr‚rrrr r,sJ  ÿ #     $*   rcCsŽd}dD]}t |¡r|}q qt d¡r.dnd}t ¡|sLt gd¢¡t|pTdd|p`|p`d|pfd|plddd�}|j|d|dd �|S) N)ÚbcryptÚ sha256_cryptr‰)Úportable_apache_24Úhost_apache_24Úlinux_apache_24ÚportableÚhostÚ apr_md5_cryptrŠ)r‹Úportable_apache_22rŒZhost_apache_22r�Zlinux_apache_22r‹rŒ)rŽr�)rZhas_os_crypt_supportZ has_backendÚ_warn_no_bcryptÚclearÚupdaterF)Z host_bestrCr‰Údefaultsrrr Ú_init_default_schemes³s,  õþr–cCsPgd¢}| t ¡¡|dd…dg|}tt|ƒ|jd�}t|tddd�S)N)r‰rŠZ sha512_cryptZ des_cryptr�Z ldap_sha1Z plaintextér�)r\r‘Z2y)ÚschemesÚdefaultZ bcrypt__ident)ÚextendrZget_supported_os_crypt_schemesÚsortedriÚindexrÚhtpasswd_defaults)r˜Z preferredrrr Ú_init_htpasswd_contextÞsùržcsªeZdZdZddef‡fdd„ Zdd„Zdd„Zd d „Zd d „Z e d ddd�dd„ƒZ dd„Z dd„Z e d ddd�dd„ƒZdd„Zdd„Ze d ddd�dd „ƒZ‡ZS)!raÇclass for reading & writing Htpasswd files. The class constructor accepts the following arguments: :type path: filepath :param path: Specifies path to htpasswd file, use to implicitly load from and save to. This class has two modes of operation: 1. It can be "bound" to a local file by passing a ``path`` to the class constructor. In this case it will load the contents of the file when created, and the :meth:`load` and :meth:`save` methods will automatically load from and save to that file if they are called without arguments. 2. Alternately, it can exist as an independant object, in which case :meth:`load` and :meth:`save` will require an explicit path to be provided whenever they are called. As well, ``autosave`` behavior will not be available. This feature is new in Passlib 1.6, and is the default if no ``path`` value is provided to the constructor. This is also exposed as a readonly instance attribute. :type new: bool :param new: Normally, if *path* is specified, :class:`HtpasswdFile` will immediately load the contents of the file. However, when creating a new htpasswd file, applications can set ``new=True`` so that the existing file (if any) will not be loaded. .. versionadded:: 1.6 This feature was previously enabled by setting ``autoload=False``. That alias has been deprecated, and will be removed in Passlib 1.8 :type autosave: bool :param autosave: Normally, any changes made to an :class:`HtpasswdFile` instance will not be saved until :meth:`save` is explicitly called. However, if ``autosave=True`` is specified, any changes made will be saved to disk immediately (assuming *path* has been set). This is also exposed as a writeable instance attribute. :type encoding: str :param encoding: Optionally specify character encoding used to read/write file and hash passwords. Defaults to ``utf-8``, though ``latin-1`` is the only other commonly encountered encoding. This is also exposed as a readonly instance attribute. :type default_scheme: str :param default_scheme: Optionally specify default scheme to use when encoding new passwords. This can be any of the schemes with builtin Apache support, OR natively supported by the host OS's :func:`crypt.crypt` function. * Builtin schemes include ``"bcrypt"`` (apache 2.4+), ``"apr_md5_crypt"`, and ``"des_crypt"``. * Schemes commonly supported by Unix hosts include ``"bcrypt"``, ``"sha256_crypt"``, and ``"des_crypt"``. In order to not have to sort out what you should use, passlib offers a number of aliases, that will resolve to the most appropriate scheme based on your needs: * ``"portable"``, ``"portable_apache_24"`` -- pick scheme that's portable across hosts running apache >= 2.4. **This will be the default as of Passlib 2.0**. * ``"portable_apache_22"`` -- pick scheme that's portable across hosts running apache >= 2.4. **This is the default up to Passlib 1.9**. * ``"host"``, ``"host_apache_24"`` -- pick strongest scheme supported by apache >= 2.4 and/or host OS. * ``"host_apache_22"`` -- pick strongest scheme supported by apache >= 2.2 and/or host OS. .. versionadded:: 1.6 This keyword was previously named ``default``. That alias has been deprecated, and will be removed in Passlib 1.8. .. versionchanged:: 1.6.3 Added support for ``"bcrypt"``, ``"sha256_crypt"``, and ``"portable"`` alias. .. versionchanged:: 1.7 Added apache 2.4 semantics, and additional aliases. :type context: :class:`~passlib.context.CryptContext` :param context: :class:`!CryptContext` instance used to create and verify the hashes found in the htpasswd file. The default value is a pre-built context which supports all of the hashes officially allowed in an htpasswd file. This is also exposed as a readonly instance attribute. .. warning:: This option may be used to add support for non-standard hash formats to an htpasswd file. However, the resulting file will probably not be usable by another application, and particularly not by Apache. :param autoload: Set to ``False`` to prevent the constructor from automatically loaded the file from disk. .. deprecated:: 1.6 This has been replaced by the *new* keyword. Instead of setting ``autoload=False``, you should use ``new=True``. Support for this keyword will be removed in Passlib 1.8. :param default: Change the default algorithm used to hash new passwords. .. deprecated:: 1.6 This has been renamed to *default_scheme* for clarity. Support for this alias will be removed in Passlib 1.8. Loading & Saving ================ .. automethod:: load .. automethod:: load_if_changed .. automethod:: load_string .. automethod:: save .. automethod:: to_string Inspection ================ .. automethod:: users .. automethod:: check_password .. automethod:: get_hash Modification ================ .. automethod:: set_password .. automethod:: delete Alternate Constructors ====================== .. automethod:: from_string Attributes ========== .. attribute:: path Path to local file that will be used as the default for all :meth:`load` and :meth:`save` operations. May be written to, initialized by the *path* constructor keyword. .. attribute:: autosave Writeable flag indicating whether changes will be automatically written to *path*. Errors ====== :raises ValueError: All of the methods in this class will raise a :exc:`ValueError` if any user name contains a forbidden character (one of ``:\r\n\t\x00``), or is longer than 255 characters. Nc svd|vr tdtdd�| d¡}|rT|tvrïrIz&HtpasswdFile.users..)r/r:rr:r ÚusersëszHtpasswdFile.userscCs|j |¡}| ||¡S)a£Set password for user; adds user if needed. :returns: * ``True`` if existing user was updated. * ``False`` if user account was added. .. versionchanged:: 1.6 This method was previously called ``update``, it was renamed to prevent ambiguity with the dictionary method. The old alias is deprecated, and will be removed in Passlib 1.8. )r¢rªÚset_hash)rrnÚpasswordrªrrr Ú set_passwordýs zHtpasswdFile.set_passwordú1.6ú1.8r°©Z deprecatedZremovedZ replacementcCs | ||¡S©zset password for user©r°©rrnr¯rrr r” szHtpasswdFile.updatecCs,z|j| |¡WSty&YdS0dS)aReturn hash stored for user, or ``None`` if user not found. .. versionchanged:: 1.6 This method was previously named ``find``, it was renamed for clarity. The old name is deprecated, and will be removed in Passlib 1.8. N)r/rrÚKeyErrorrqrrr Úget_hashs zHtpasswdFile.get_hashcCs<trt|tƒr| |j¡}| |¡}| ||¡}| ¡|S)zã semi-private helper which allows writing a hash directly; adds user if needed. .. warning:: does not (currently) do any validation of the hash string .. versionadded:: 1.7 )rr|Ústrr}r*rrrbrd)rrnrªrarrr r®s    zHtpasswdFile.set_hashr¸cCs | |¡S©zreturn hash for user©r¸rqrrr Úfind1szHtpasswdFile.findcCs4z|j| |¡=Wnty&YdS0| ¡dS)zƒDelete user's entry. :returns: * ``True`` if user deleted. * ``False`` if user not found. FT)r/rrr·rdrqrrr Údelete8s  zHtpasswdFile.deletecCsz| |¡}|j |¡}|dur"dSt|tƒr8| |j¡}|j ||¡\}}|rv|durv||jvsdJ‚||j|<|  ¡|S)aM Verify password for specified user. If algorithm marked as deprecated by CryptContext, will automatically be re-hashed. :returns: * ``None`` if user not found. * ``False`` if user found, but password does not match. * ``True`` if user found and password matches. .. versionchanged:: 1.6 This method was previously called ``verify``, it was renamed to prevent ambiguity with the :class:`!CryptContext` method. The old alias is deprecated, and will be removed in Passlib 1.8. N) rrr/r r|rr}r*r¢Zverify_and_updaterd)rrnr¯rªÚokZnew_hashrrr Úcheck_passwordFs      zHtpasswdFile.check_passwordr¿cCs | ||¡S©zverify password for user©r¿r¶rrr ÚverifyeszHtpasswdFile.verify)r5rƒr„r…Úhtpasswd_contextr2rKrjr­r°r r”r¸r®r¼r½r¿rÂÚ __classcell__rrr¤r rs.9ÿ  ÿ ÿcsèeZdZdZdZd+‡fdd„ Zdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z d,dd„Z de fdd„Zedddd�dd„ƒZd-dd„Zde fdd„Zedddd�d d!„ƒZd.d"d#„Zd$d%„Zde fd&d'„Zeddd(d�d)d*„ƒZ‡ZS)/raÎclass for reading & writing Htdigest files. The class constructor accepts the following arguments: :type path: filepath :param path: Specifies path to htdigest file, use to implicitly load from and save to. This class has two modes of operation: 1. It can be "bound" to a local file by passing a ``path`` to the class constructor. In this case it will load the contents of the file when created, and the :meth:`load` and :meth:`save` methods will automatically load from and save to that file if they are called without arguments. 2. Alternately, it can exist as an independant object, in which case :meth:`load` and :meth:`save` will require an explicit path to be provided whenever they are called. As well, ``autosave`` behavior will not be available. This feature is new in Passlib 1.6, and is the default if no ``path`` value is provided to the constructor. This is also exposed as a readonly instance attribute. :type default_realm: str :param default_realm: If ``default_realm`` is set, all the :class:`HtdigestFile` methods that require a realm will use this value if one is not provided explicitly. If unset, they will raise an error stating that an explicit realm is required. This is also exposed as a writeable instance attribute. .. versionadded:: 1.6 :type new: bool :param new: Normally, if *path* is specified, :class:`HtdigestFile` will immediately load the contents of the file. However, when creating a new htpasswd file, applications can set ``new=True`` so that the existing file (if any) will not be loaded. .. versionadded:: 1.6 This feature was previously enabled by setting ``autoload=False``. That alias has been deprecated, and will be removed in Passlib 1.8 :type autosave: bool :param autosave: Normally, any changes made to an :class:`HtdigestFile` instance will not be saved until :meth:`save` is explicitly called. However, if ``autosave=True`` is specified, any changes made will be saved to disk immediately (assuming *path* has been set). This is also exposed as a writeable instance attribute. :type encoding: str :param encoding: Optionally specify character encoding used to read/write file and hash passwords. Defaults to ``utf-8``, though ``latin-1`` is the only other commonly encountered encoding. This is also exposed as a readonly instance attribute. :param autoload: Set to ``False`` to prevent the constructor from automatically loaded the file from disk. .. deprecated:: 1.6 This has been replaced by the *new* keyword. Instead of setting ``autoload=False``, you should use ``new=True``. Support for this keyword will be removed in Passlib 1.8. Loading & Saving ================ .. automethod:: load .. automethod:: load_if_changed .. automethod:: load_string .. automethod:: save .. automethod:: to_string Inspection ========== .. automethod:: realms .. automethod:: users .. automethod:: check_password(user[, realm], password) .. automethod:: get_hash Modification ============ .. automethod:: set_password(user[, realm], password) .. automethod:: delete .. automethod:: delete_realm Alternate Constructors ====================== .. automethod:: from_string Attributes ========== .. attribute:: default_realm The default realm that will be used if one is not provided to methods that require it. By default this is ``None``, in which case an explicit realm must be provided for every method call. Can be written to. .. attribute:: path Path to local file that will be used as the default for all :meth:`load` and :meth:`save` operations. May be written to, initialized by the *path* constructor keyword. .. attribute:: autosave Writeable flag indicating whether changes will be automatically written to *path*. Errors ====== :raises ValueError: All of the methods in this class will raise a :exc:`ValueError` if any user name or realm contains a forbidden character (one of ``:\r\n\t\x00``), or is longer than 255 characters. Nc s"||_tt|ƒj|fi|¤ŽdSr9)Ú default_realmr£rr2)rrrÅrr¤rr r2szHtdigestFile.__init__cCs<| ¡ t¡}t|ƒdkr&td|ƒ‚|\}}}||f|fS)Nr—z/malformed htdigest file (error reading line %d)r¥)rrr`r¨rnrsrªrrr rK s ÿ zHtdigestFile._parse_recordcCs|\}}td|||ƒS)Nz %s:%s:%s r©)rr\rªrnrsrrr rjszHtdigestFile._render_recordcCs"|dur|j}|durtdƒ‚|S)NzGyou must specify a realm explicitly, or set the default_realm attribute)rÅrrtrrr Ú_require_realms zHtdigestFile._require_realmcCs| |¡}| |d¡S)Nrs)rÆrprtrrr rus zHtdigestFile._encode_realmcCs| |¡| |¡fSr9)rrru©rrnrsrrr Ú _encode_key#szHtdigestFile._encode_keycs&tdd„ˆjDƒƒ}‡fdd„|DƒS)z%Return list of all realms in databasecss|]}|dVqdS)rJNr©ryr\rrr r{,rIz&HtdigestFile.realms..csg|]}ˆ |¡‘qSrr«)ryrsr:rr r¬-rIz'HtdigestFile.realms..)rir/)rÚrealmsrr:r rÊ*szHtdigestFile.realmscs ˆ ˆ¡‰‡‡fdd„ˆjDƒS)z®Return list of all users in specified realm. * uses ``self.default_realm`` if no realm explicitly provided. * returns empty list if realm not found. cs&g|]}|dˆkrˆ |d¡‘qS)rJrr«rÉ©rsrrr r¬6s ÿz&HtdigestFile.users..)rur/rtrrËr r­/s zHtdigestFile.userscCs>|turd|}}| |¡}tj||||jd�}| |||¡S)aŸSet password for user; adds user & realm if needed. If ``self.default_realm`` has been set, this may be called with the syntax ``set_password(user, password)``, otherwise it must be called with all three arguments: ``set_password(user, realm, password)``. :returns: * ``True`` if existing user was updated * ``False`` if user account added. N©r*)Ú_UNSETrÆrrªr*r®©rrnrsr¯rªrrr r°Qs   zHtdigestFile.set_passwordr±r²r°r³cCs| |||¡Sr´rµ©rrnrsr¯rrr r”dszHtdigestFile.updatecCs8| ||¡}|j |¡}|dur$dStr4| |j¡}|S)a�Return :class:`~passlib.hash.htdigest` hash stored for user. * uses ``self.default_realm`` if no realm explicitly provided. * returns ``None`` if user or realm not found. .. versionchanged:: 1.6 This method was previously named ``find``, it was renamed for clarity. The old name is deprecated, and will be removed in Passlib 1.8. N)rÈr/r rr�r*)rrnrsr\rªrrr r¸js   zHtdigestFile.get_hashcCsP|turd|}}tr,t|tƒr,| |j¡}| ||¡}| ||¡}| ¡|S)aÈ semi-private helper which allows writing a hash directly; adds user & realm if needed. If ``self.default_realm`` has been set, this may be called with the syntax ``set_hash(user, hash)``, otherwise it must be called with all three arguments: ``set_hash(user, realm, hash)``. .. warning:: does not (currently) do any validation of the hash string .. versionadded:: 1.7 N) rÍrr|r¹r}r*rÈrbrd)rrnrsrªr\rarrr r®}s    zHtdigestFile.set_hashr¸cCs | ||¡Srºr»rÇrrr r¼—szHtdigestFile.findcCs:| ||¡}z |j|=Wnty,YdS0| ¡dS)záDelete user's entry for specified realm. if realm is not specified, uses ``self.default_realm``. :returns: * ``True`` if user deleted, * ``False`` if user not found in realm. FT)rÈr/r·rd)rrnrsr\rrr r½žs   zHtdigestFile.deletecsB| ˆ¡‰|j}‡fdd„|Dƒ}|D] }||=q&| ¡t|ƒS)z±Delete all users for specified realm. if realm is not specified, uses ``self.default_realm``. :returns: number of users deleted (0 if realm not found) csg|]}|dˆkr|‘qS)rJrrÉ©rsrr r¬¸rIz-HtdigestFile.delete_realm..)rur/rdr)rrsrWÚkeysr\rrÐr Ú delete_realm¯s zHtdigestFile.delete_realmcCsX|turd|}}| |¡}| |¡}|j ||f¡}|durBdStj|||||jd�S)aêVerify password for specified user + realm. If ``self.default_realm`` has been set, this may be called with the syntax ``check_password(user, password)``, otherwise it must be called with all three arguments: ``check_password(user, realm, password)``. :returns: * ``None`` if user or realm not found. * ``False`` if user found, but password does not match. * ``True`` if user found and password matches. .. versionchanged:: 1.6 This method was previously called ``verify``, it was renamed to prevent ambiguity with the :class:`!CryptContext` method. The old alias is deprecated, and will be removed in Passlib 1.8. NrÌ)rÍrrrur/r rrÂr*rÎrrr r¿¾s    ÿzHtdigestFile.check_passwordr¿cCs| |||¡SrÀrÁrÏrrr rÂÛszHtdigestFile.verify)NN)N)N)N)r5rƒr„r…rÅr2rKrjrÆrurÈrÊr­rÍr°r r”r¸r®r¼r½rÒr¿rÂrÄrrr¤r rrs: "ÿ  ÿ  ÿ)/r…Z __future__rZloggingZ getLoggerr5rPr?ÚwarningsrZpasslibrrZpasslib.contextrZ passlib.excrZ passlib.hashrZ passlib.utilsr r r Zpasslib.utils.decorr Zpasslib.utils.compatr rrrÚ__all__ÚobjectrÍr§rOrxrRrSrrir’r–r�ržrÃrrrrrr ÚsB      þ)-c