
    h$[                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJrJrJrJr  S SKJr  S SKJr  S	rS
rS rS'S jrS(S jrS(S jrS(S jr\R@                  S 5       r!\R@                  S 5       r"\" \5      S 5       r#S'S jr$S r%S)S jr&S r' " S S5      r( " S S\(5      r) " S S\)5      r* " S S\(5      r+ " S S \(5      r, " S! S"\,5      r- " S# S$\(5      r. " S% S&\(5      r/g)*    N)settings)ImproperlyConfigured)setting_changed)receiver)RANDOM_STRING_CHARSconstant_time_compareget_random_stringpbkdf2)import_string)gettext_noop!(   c                 L    U SL =(       d    U R                  [        5      (       + $ )zj
Return True if this password wasn't generated by
User.set_unusable_password(), i.e. make_password(None).
N)
startswithUNUSABLE_PASSWORD_PREFIX)encodeds    M/var/www/html/env/lib/python3.13/site-packages/django/contrib/auth/hashers.pyis_password_usabler      s"    
 d?N'"4"45M"NNN    c                    U SL =(       d    [        U5      (       + n[        U5      n [        U5      nU(       a  [	        [        [        5      5        gWR                  UR                  :g  nU=(       d    UR                  U5      nUR                  X5      nU(       d  U(       d  U(       a  UR                  X5        Xv4$ ! [         a    Sn Nf = f)z
Return two booleans. The first is whether the raw password matches the
three part encoded digest, and the second whether to regenerate the
password.
NT)FF)r   
get_hasheridentify_hasher
ValueErrormake_passwordr	   UNUSABLE_PASSWORD_SUFFIX_LENGTH	algorithmmust_updateverifyharden_runtime)passwordr   	preferredfake_runtimehasherhasher_changedr   
is_corrects           r   verify_passwordr&   $   s     t#F+=g+F'FL9%I )
  	'(GHI%%)<)<<N BI$9$9'$BKx1J nh0""-  s   C   CCc                 X    [        XUS9u  pEU(       a  U(       a  U(       a  U" U 5        U$ )z
Return a boolean of whether the raw password matches the three part encoded
digest.

If setter is specified, it'll be called when you need to regenerate the
password.
r!   r&   r    r   setterr!   r%   r   s         r   check_passwordr,   H   s(     .h9UJ*xr   c                 t   #    [        XUS9u  pEU(       a  U(       a  U(       a  U" U 5      I Sh  vN   U$  N7f)zSee check_password().r(   Nr)   r*   s         r   acheck_passwordr.   V   s4     -h9UJ*X 	s   -868c                    U c  [         [        [        5      -   $ [        U [        [
        45      (       d!  [        S[        U 5      R                  -  5      e[        U5      nU=(       d    UR                  5       nUR                  X5      $ )ad  
Turn a plain-text password into a hash for database storage

Same as encode() but generate a new random salt. If password is None then
return a concatenation of UNUSABLE_PASSWORD_PREFIX and a random string,
which disallows logins. Additional random string reduces chances of gaining
access to staff or superuser accounts. See ticket #20079 for more info.
z+Password must be a string or bytes, got %s.)r   r	   r   
isinstancebytesstr	TypeErrortype__qualname__r   saltencode)r    r6   r#   s      r   r   r   ^   s     '*;++
 
 	
 h--9DN<W<WW
 	
 F 6;;=D==((r   c                      / n [         R                   HE  n[        U5      nU" 5       n[        US5      (       d  [	        SU-  5      eU R                  U5        MG     U $ )Nr   z,hasher doesn't specify an algorithm name: %s)r   PASSWORD_HASHERSr   getattrr   append)hashershasher_path
hasher_clsr#   s       r   get_hashersr?   t   s_    G00";/
v{++&>L  	v 1 Nr   c                  V    [        5        V s0 s H  o R                  U _M     sn $ s  sn f N)r?   r   )r#   s    r   get_hashers_by_algorithmrB      s%    3>=A=f$=AAAs   &c                 b    U S:X  a)  [         R                  5         [        R                  5         g g )Nr9   )r?   cache_clearrB   )settingkwargss     r   reset_hashersrG      s(    $$! ,,. %r   c                     [        U S5      (       a  U $ U S:X  a  [        5       S   $ [        5       n X   $ ! [         a    [	        SU -  5      ef = f)z
Return an instance of a loaded password hasher.

If algorithm is 'default', return the default hasher. Lazily import hashers
specified in the project's settings file if needed.
r   defaultr   z\Unknown password hashing algorithm '%s'. Did you specify it in the PASSWORD_HASHERS setting?)hasattrr?   rB   KeyErrorr   )r   r<   s     r   r   r      sm     y+&&	i	}Q +,	%% 	&' 	s	   6 Ac                    [        U 5      S:X  a  SU ;  d%  [        U 5      S:X  a  U R                  S5      (       a  SnO=[        U 5      S:X  a  U R                  S5      (       a  SnOU R                  SS	5      S
   n[        U5      $ )z
Return an instance of a loaded password hasher.

Identify hasher algorithm by examining encoded hash, and call
get_hasher() to return hasher. Raise ValueError if
algorithm cannot be identified, or if hasher is not loaded.
    $%   zmd5$$unsalted_md5.   zsha1$$unsalted_sha1   r   )lenr   splitr   )r   r   s     r   r   r      sy     	Gs'1Gw11'::"		W	 2 28 < <#	MM#q)!,	i  r   c                 4    U SU nX2[        XS 5      -  -  nU$ )z{
Return the given hash, with only the first ``show`` number shown. The
rest are masked with ``char`` for security reasons.
N)rT   )hashshowcharmaskeds       r   	mask_hashr[      s*    
 %4[F
Se%%%FMr   c                 f    [        U 5      [        R                  " [        [        5      5      -  U:  $ rA   )rT   mathlog2r   )r6   expected_entropys     r   must_update_saltr`      s&    t9tyy%8!9::=MMMr   c                   Z    \ rS rSrSrSrSrSrS rS r	S r
S rS	 rS
 rS rS rS rSrg)BasePasswordHasher   z
Abstract base class for password hashers

When creating your own hasher, you need to override algorithm,
verify(), encode() and safe_summary().

PasswordHasher objects are immutable.
N   c                    U R                   bY  [        U R                   [        [        45      (       a  U R                   u  pOU R                   n [        R
                  " U5      nU$ [        SU R                  R                  -  5      e! [         a,  n[        SU R                  R                  < SU< 35      eS nAff = f)NzCouldn't load z algorithm library: z-Hasher %r doesn't specify a library attribute)
libraryr0   tuplelist	importlibimport_moduleImportErrorr   	__class____name__)selfnamemod_pathmodulees        r   _load_library BasePasswordHasher._load_library   s    <<#$,,66!%h<<"00: M;dnn>U>UU
 	
   ~~..3 s   B	 	
B?'B::B?c                     [         R                  " U R                  [         R                  " [	        [
        5      5      -  5      n[        U[
        S9$ )zj
Generate a cryptographically secure nonce salt in ASCII with an entropy
of at least `salt_entropy` bits.
)allowed_chars)r]   ceilsalt_entropyr^   rT   r   r	   )rn   
char_counts     r   r6   BasePasswordHasher.salt   s:     YYt00499SAT=U3VVW
 ;NOOr   c                     [        S5      e)z'Check if the given password is correct.z?subclasses of BasePasswordHasher must provide a verify() methodNotImplementedErrorrn   r    r   s      r   r   BasePasswordHasher.verify   s    !M
 	
r   c                 P    Uc  [        S5      eU(       a  SU;   a  [        S5      eg )Nzpassword must be provided.rN   z+salt must be provided and cannot contain $.)r3   r   rn   r    r6   s      r   _check_encode_args%BasePasswordHasher._check_encode_args   s.    899sd{JKK #r   c                     [        S5      e)z
Create an encoded database value.

The result is normally formatted as "algorithm$salt$hash" and
must be fewer than 128 characters.
z@subclasses of BasePasswordHasher must provide an encode() methodr|   r   s      r   r7   BasePasswordHasher.encode  s     "N
 	
r   c                     [        S5      e)z
Return a decoded database value.

The result is a dictionary and should contain `algorithm`, `hash`, and
`salt`. Extra keys can be algorithm specific like `iterations` or
`work_factor`.
z@subclasses of BasePasswordHasher must provide a decode() method.r|   rn   r   s     r   decodeBasePasswordHasher.decode  s     "N
 	
r   c                     [        S5      e)z
Return a summary of safe values.

The result is a dictionary and will be used where the password field
must be displayed to construct a safe representation of the password.
zEsubclasses of BasePasswordHasher must provide a safe_summary() methodr|   r   s     r   safe_summaryBasePasswordHasher.safe_summary  s     "S
 	
r   c                     g)NF r   s     r   r   BasePasswordHasher.must_update$  s    r   c                 0    [         R                  " S5        g)a  
Bridge the runtime gap between the work factor supplied in `encoded`
and the work factor suggested by this hasher.

Taking PBKDF2 as an example, if `encoded` contains 20000 iterations and
`self.iterations` is 30000, this method should run password through
another 10000 iterations of PBKDF2. Similar approaches should exist
for any hasher that has a work factor. If not, this method should be
defined as a no-op to silence the warning.
zIsubclasses of BasePasswordHasher should provide a harden_runtime() methodN)warningswarnr~   s      r   r   !BasePasswordHasher.harden_runtime'  s     	W	
r   r   )rm   
__module__r5   __firstlineno____doc__r   rf   rx   rs   r6   r   r   r7   r   r   r   r   __static_attributes__r   r   r   rb   rb      sG     IGL
$P
L	


	

r   rb   c                   `    \ rS rSrSrSrSr\R                  r	SS jr
S rS rS	 rS
 rS rSrg)PBKDF2PasswordHasheri7  z
Secure password hashing using the PBKDF2 algorithm (recommended)

Configured to use PBKDF2 + HMAC + SHA256.
The result is a 64 byte binary string.  Iterations may be changed
safely but you must rename the algorithm if you change SHA256.
pbkdf2_sha256ipF Nc                     U R                  X5        U=(       d    U R                  n[        XX0R                  S9n[        R
                  " U5      R                  S5      R                  5       nSU R                  X2U4-  $ )N)digestasciiz%s$%d$%s$%s)	r   
iterationsr
   r   base64	b64encoder   stripr   )rn   r    r6   r   rW   s        r   r7   PBKDF2PasswordHasher.encodeD  sh    /24??
hjE%,,W5;;=
$GGGr   c                 n    UR                  SS5      u  p#pEX R                  :X  d   eUU[        U5      US.$ )NrN      )r   rW   r   r6   rU   r   int)rn   r   r   r   r6   rW   s         r   r   PBKDF2PasswordHasher.decodeK  sA    ,3MM#q,A)	tNN***"j/	
 	
r   c                 j    U R                  U5      nU R                  XS   US   5      n[        X$5      $ Nr6   r   r   r7   r   rn   r    r   decoded	encoded_2s        r   r   PBKDF2PasswordHasher.verifyU  s4    ++g&KK&/7<;PQ	$W88r   c                     U R                  U5      n[        S5      US   [        S5      US   [        S5      [        US   5      [        S5      [        US   5      0$ )Nr   r   r6   rW   r   _r[   rn   r   r   s      r   r   !PBKDF2PasswordHasher.safe_summaryZ  sZ    ++g&kNGK0lOW\2fIy1fIy1	
 	
r   c                     U R                  U5      n[        US   U R                  5      nUS   U R                  :g  =(       d    U$ r   )r   r`   rx   r   )rn   r   r   update_salts       r   r    PBKDF2PasswordHasher.must_updatec  s?    ++g&&wv8I8IJ%8H[Hr   c                     U R                  U5      nU R                  US   -
  nUS:  a  U R                  XS   U5        g g )Nr   r   r6   )r   r   r7   )rn   r    r   r   extra_iterationss        r   r   #PBKDF2PasswordHasher.harden_runtimeh  sD    ++g&??W\-BBaKK&/3CD  r   r   rA   )rm   r   r5   r   r   r   r   hashlibsha256r   r7   r   r   r   r   r   r   r   r   r   r   r   7  s=      IJ^^FH
9

I
Er   r   c                   4    \ rS rSrSrSr\R                  rSr	g)PBKDF2SHA1PasswordHasherio  z
Alternate PBKDF2 hasher which uses SHA1, the default PRF
recommended by PKCS #5. This is compatible with other
implementations of PBKDF2, such as openssl's
PKCS5_PBKDF2_HMAC_SHA1().
pbkdf2_sha1r   N)
rm   r   r5   r   r   r   r   sha1r   r   r   r   r   r   r   o  s     I\\Fr   r   c                   V    \ rS rSrSrSrSrSrSrSr	S r
S rS	 rS
 rS rS rS rSrg)Argon2PasswordHasheri{  z
Secure password hashing using the argon2 algorithm.

This is the winner of the Password Hashing Competition 2013-2015
(https://password-hashing.net). It requires the argon2-cffi library which
depends on native C code and might cause portability issues.
argon2   i     c           
      X   U R                  5       nU R                  5       nUR                  R                  UR	                  5       UR	                  5       UR
                  UR                  UR                  UR                  UR                  S9nU R                  UR                  S5      -   $ )N)	time_costmemory_costparallelismhash_lenr4   r   )rs   params	low_levelhash_secretr7   r   r   r   r   r4   r   r   )rn   r    r6   r   r   datas         r   r7   Argon2PasswordHasher.encode  s    ##%++OOKKM&&****__ , 
 ~~G 444r   c           
         U R                  5       nUR                  SS5      u  p4X0R                  :X  d   eUR                  SU-   5      nUR                  S5      GtpgpUS[	        U5      * S-  -  -  n[
        R                  " U5      R                  S5      n
UU	UR                  UR                  U
UR                  UUR                  US.	$ )NrN   rS   =   latin1)	r   rW   r   r   r6   r   varietyversionr   )rs   rU   r   extract_parametersrT   r   	b64decoder   r   r   r   r   )rn   r   r   r   restr   r   r   b64saltrW   r6   s              r   r   Argon2PasswordHasher.decode  s    ##%!--Q/	NN*****3:6%)ZZ_"W33w<-!+,,(//9"!--!--))~~

 
	
r   c                     U R                  5       nUR                  SS5      u  pEX@R                  :X  d   e UR                  5       R	                  SU-   U5      $ ! UR
                  R                   a     gf = f)NrN   rS   F)rs   rU   r   PasswordHasherr   
exceptionsVerificationError)rn   r    r   r   r   r   s         r   r   Argon2PasswordHasher.verify  su    ##%!--Q/	NN***	((*11#*hGG  22 		s   "A A76A7c                 ,   U R                  U5      n[        S5      US   [        S5      US   [        S5      US   [        S5      US   [        S5      US   [        S5      US   [        S	5      [        US	   5      [        S
5      [        US
   5      0$ )Nr   r   r   zmemory costr   z	time costr   r   r6   rW   r   r   s      r   r   !Argon2PasswordHasher.safe_summary  s    ++g&kNGK0iL'),iL'),mgm4kNGK0mgm4fIy1fIy1	
 		
r   c                     U R                  U5      nUS   nU R                  5       nUR                  Ul        [        US   U R                  5      nX4:g  =(       d    U$ )Nr   r6   )r   r   salt_lenr`   rx   )rn   r   r   current_params
new_paramsr   s         r   r    Argon2PasswordHasher.must_update  sY    ++g& *[[]
 -55
&wv8I8IJ,<<r   c                     g rA   r   r~   s      r   r   #Argon2PasswordHasher.harden_runtime       	r   c           
         U R                  5       nUR                  UR                  R                  R                  UR                  R
                  UR                  UR                  U R                  U R                  U R                  S9$ )N)r4   r   r   r   r   r   r   )rs   
Parametersr   TypeIDARGON2_VERSIONDEFAULT_RANDOM_SALT_LENGTHDEFAULT_HASH_LENGTHr   r   r   )rn   r   s     r   r   Argon2PasswordHasher.params  sw    ##%  !!&&))$$3366//nn(((( ! 
 	
r   r   N)rm   r   r5   r   r   r   rf   r   r   r   r7   r   r   r   r   r   r   r   r   r   r   r   r   {  sE     IGIKK5
*
=

r   r   c                   f    \ rS rSrSrSr\R                  rSr	Sr
S rS rS rS	 rS
 rS rS rSrg)BCryptSHA256PasswordHasheri  a  
Secure password hashing using the bcrypt algorithm (recommended)

This is considered by many to be the most secure algorithm but you
must first install the bcrypt library.  Please be warned that
this library depends on native C code and might cause portability
issues.
bcrypt_sha256)bcryptr      c                 X    U R                  5       nUR                  U R                  5      $ rA   )rs   gensaltrounds)rn   r   s     r   r6   BCryptSHA256PasswordHasher.salt  s#    ##%~~dkk**r   c                 (   U R                  5       nUR                  5       nU R                  b3  [        R                  " U R                  U5      R                  5       5      nUR                  X5      nU R                  < SUR                  S5      < 3$ )NrN   r   )rs   r7   r   binasciihexlifyhashpwr   r   )rn   r    r6   r   r   s        r   r7   !BCryptSHA256PasswordHasher.encode  sp    ##%??$ ;;"''H(=(D(D(FGH}}X,..$++g*>??r   c                 ~    UR                  SS5      u  p#pEnX R                  :X  d   eUUUSS  US S [        U5      S.$ )NrN   r      )r   algostrchecksumr6   work_factorr   )rn   r   r   emptyr  r  r   s          r   r   !BCryptSHA256PasswordHasher.decode   sS    7>}}S!7L4	'NN***"RS	"I{+
 	
r   c                     UR                  SS5      u  p4X0R                  :X  d   eU R                  XR                  S5      5      n[        X%5      $ )NrN   rS   r   )rU   r   r7   r   )rn   r    r   r   r   r   s         r   r   !BCryptSHA256PasswordHasher.verify  sF    !--Q/	NN***KK++g*>?	$W88r   c                     U R                  U5      n[        S5      US   [        S5      US   [        S5      [        US   5      [        S5      [        US   5      0$ )Nr   work factorr  r6   r  r   r   s      r   r   'BCryptSHA256PasswordHasher.safe_summary  s\    ++g&kNGK0mgm4fIy1jM9WZ%89	
 	
r   c                 H    U R                  U5      nUS   U R                  :g  $ )Nr  )r   r   r   s      r   r   &BCryptSHA256PasswordHasher.must_update  s$    ++g&}%44r   c                    UR                  SS5      u  p4US S nUR                  S5      S   nSU R                  [        U5      -
  -  S-
  nUS:  a.  U R                  XR                  S5      5        US-  nUS:  a  M-  g g )NrN   rS      r   r   r   )rU   r   r   r7   )rn   r    r   r   r   r6   r   diffs           r   r   )BCryptSHA256PasswordHasher.harden_runtime  s{    --Q'CRyC#T[[3v;./!3QhKK++g"67AID Qhr   r   N)rm   r   r5   r   r   r   r   r   r   rf   r   r6   r7   r   r   r   r   r   r   r   r   r   r   r     sE      I^^F"GF+
@	
9
5r   r   c                        \ rS rSrSrSrSrSrg)BCryptPasswordHasheri)  a  
Secure password hashing using the bcrypt algorithm

This is considered by many to be the most secure algorithm but you
must first install the bcrypt library.  Please be warned that
this library depends on native C code and might cause portability
issues.

This hasher does not first hash the password which means it is subject to
bcrypt's 72 bytes password truncation. Most use cases should prefer the
BCryptSHA256PasswordHasher.
r   Nr   )rm   r   r5   r   r   r   r   r   r   r   r   r  r  )  s     IFr   r  c                   T    \ rS rSrSrSrSrSrSrSr	SS	 jr
S
 rS rS rS rS rSrg)ScryptPasswordHasheri;  z5
Secure password hashing using the Scrypt algorithm.
scryptr   r      i @  Nc           
         U R                  X5        U=(       d    U R                  nU=(       d    U R                  nU=(       d    U R                  n[        R
                  " UR                  5       UR                  5       UUUU R                  SS9n[        R                  " U5      R                  S5      R                  5       nSU R                  X2XEU4-  $ )N@   )r6   nrpmaxmemdklenr   z%s$%d$%s$%d$%d$%s)r   r  
block_sizer   r   r  r7   r  r   r   r   r   r   )rn   r    r6   r  r  r  hash_s          r   r7   ScryptPasswordHasher.encodeF  s    /!!! !!!OO;;
   '..w7==?"dnnaqU%KKKr   c                     UR                  SS5      u  p#pEpgX R                  :X  d   eU[        U5      U[        U5      [        U5      US.$ )NrN      )r   r  r6   r  r   rW   r   )rn   r   r   r  r6   r  r   r  s           r   r   ScryptPasswordHasher.decodeW  sY    GN}}H
D	+ NN***"{+j/{+
 	
r   c                 |    U R                  U5      nU R                  UUS   US   US   US   5      n[        X$5      $ )Nr6   r  r  r   r   r   s        r   r   ScryptPasswordHasher.verifye  sM    ++g&KKFOM"L!M"
	 %W88r   c                     U R                  U5      n[        S5      US   [        S5      US   [        S5      US   [        S5      US   [        S5      [        US   5      [        S5      [        US   5      0$ )	Nr   r	  r  z
block sizer  r   r6   rW   r   r   s      r   r   !ScryptPasswordHasher.safe_summaryp  sx    ++g&kNGK0mgm4lOW\2mgm4fIy1fIy1
 	
r   c                     U R                  U5      nUS   U R                  :g  =(       d+    US   U R                  :g  =(       d    US   U R                  :g  $ )Nr  r  r   )r   r  r  r   r   s      r   r    ScryptPasswordHasher.must_update{  sV    ++g&M"d&6&66 :|$7:}%)9)99	
r   c                     g rA   r   r~   s      r   r   #ScryptPasswordHasher.harden_runtime  r   r   r   )NNN)rm   r   r5   r   r   r   r  r  r   r  r7   r   r   r   r   r   r   r   r   r   r  r  ;  sA     IJFKKL"
	9	

r   r  c                   @    \ rS rSrSrSrS rS rS rS r	S r
S	 rS
rg)MD5PasswordHasheri  z=
The Salted MD5 password hashing algorithm (not recommended)
md5c                     U R                  X5        [        R                  " X!-   R                  5       5      R	                  5       nU R
                  < SU< SU< 3$ )NrN   )r   r   r.  r7   	hexdigestr   )rn   r    r6   rW   s       r   r7   MD5PasswordHasher.encode  sC    /{{DO3356@@B!^^T488r   c                 Z    UR                  SS5      u  p#nX R                  :X  d   eUUUS.$ )NrN   r   )r   rW   r6   )rU   r   )rn   r   r   r6   rW   s        r   r   MD5PasswordHasher.decode  s:     'c1 5	NN***"
 	
r   c                 b    U R                  U5      nU R                  XS   5      n[        X$5      $ Nr6   r   r   s        r   r   MD5PasswordHasher.verify  s-    ++g&KK&/:	$W88r   c           	          U R                  U5      n[        S5      US   [        S5      [        US   SS9[        S5      [        US   5      0$ )Nr   r6   r   )rX   rW   r   r   s      r   r   MD5PasswordHasher.safe_summary  sN    ++g&kNGK0fIyq9fIy1
 	
r   c                 V    U R                  U5      n[        US   U R                  5      $ r5  )r   r`   rx   r   s      r   r   MD5PasswordHasher.must_update  s'    ++g&1B1BCCr   c                     g rA   r   r~   s      r   r    MD5PasswordHasher.harden_runtime  s    r   r   N)rm   r   r5   r   r   r   r7   r   r   r   r   r   r   r   r   r   r-  r-    s-     I9

9

Dr   r-  )rI   )NrI   )r"  *)0r   r   	functoolsr   ri   r]   r   django.confr   django.core.exceptionsr   django.core.signalsr   django.dispatchr   django.utils.cryptor   r   r	   r
   django.utils.module_loadingr   django.utils.translationr   r   r   r   r   r&   r,   r.   r   	lru_cacher?   rB   rG   r   r   r[   r`   rb   r   r   r   r   r  r  r-  r   r   r   <module>rG     s9            7 / $  6 6   
O!#H), 
 
 B B 
// /2!,N
h
 h
V5E- 5Ep	3 	c
- c
LE!3 EP5 $K- K\'* 'r   