
    Dvg$                     f   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZmZ d dlmZmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ e j        d             Zd ZddZddZddZddZ eee           Z! G d d          Z"d Z# G d d          Z$ G d d          Z% G d d          Z&dS )    N)SequenceMatcher)Path)settings)FieldDoesNotExistImproperlyConfiguredValidationError)cached_propertylazy)format_htmlformat_html_join)import_string)gettext)ngettextc                  4    t          t          j                  S N)get_password_validatorsr   AUTH_PASSWORD_VALIDATORS     d/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/auth/password_validation.pyget_default_password_validatorsr      s    "8#DEEEr   c                     g }| D ]p}	 t          |d                   }n(# t          $ r d}t          ||d         z            w xY w|                     |di |                    di                      q|S )NNAMEzZThe module in NAME could not be imported: %s. Check your AUTH_PASSWORD_VALIDATORS setting.OPTIONSr   )r   ImportErrorr   appendget)validator_config
validators	validatorklassmsgs        r   r   r      s    J% 	A 	A		@!)F"344EE 	@ 	@ 	@4  'sYv->'>???	@ 	%%??)--	2">">??@@@@s	   %Ac                     g }|t                      }|D ]E}	 |                    | |           # t          $ r}|                    |           Y d}~>d}~ww xY w|rt          |          dS )z
    Validate that the password meets all validator requirements.

    If the password is valid, return ``None``.
    If the password is invalid, raise ValidationError with all error messages.
    N)r   validater   r   )passworduserpassword_validatorserrorsr    errors         r   validate_passwordr*   )   s     F"=??( ! !		!x.... 	! 	! 	!MM%        	! &f%%%& &s   /
AAAc                 l    |t                      }|D ] }t          |dd           } || |           !dS )zy
    Inform all validators that have implemented a password_changed() method
    that the password has been changed.
    Npassword_changedc                      d S r   r   )as    r   <lambda>z"password_changed.<locals>.<lambda>D   s    T r   )r   getattr)r%   r&   r'   r    r,   s        r   r,   r,   <   sZ    
 "=??( ) )	"9.@//RR4(((() )r   c                     g }| t                      } | D ])}|                    |                                           *|S )zG
    Return a list of all help texts of all configured validators.
    )r   r   get_help_text)r'   
help_textsr    s      r   password_validators_help_textsr4   H   sS     J"=??( 5 5	)11334444r   c                 ~    t          |           }t          ddd |D                       }|rt          d|          ndS )z`
    Return an HTML string with all help texts of all configured validators
    in an <ul>.
     z<li>{}</li>c              3      K   | ]}|fV  d S r   r   ).0	help_texts     r   	<genexpr>z6_password_validators_help_text_html.<locals>.<genexpr>[   s$      EEYYLEEEEEEr   z<ul>{}</ul>)r4   r   r   )r'   r3   
help_itemss      r   #_password_validators_help_text_htmlr<   T   sT    
 00CDDJ!
MEE*EEE J 6@G;}j111RGr   c                   (    e Zd ZdZddZddZd ZdS )	MinimumLengthValidatorz<
    Validate that the password is of a minimum length.
       c                     || _         d S r   )
min_length)selfrA   s     r   __init__zMinimumLengthValidator.__init__h   s    $r   Nc                     t          |          | j        k     r-t          t          dd| j                  dd| j        i          d S )NzNThis password is too short. It must contain at least %(min_length)d character.zOThis password is too short. It must contain at least %(min_length)d characters.password_too_shortrA   codeparams)lenrA   r   r   rB   r%   r&   s      r   r$   zMinimumLengthValidator.validatek   s_    x==4?**!01O  *$do6
 
 
 
 +*r   c                 B    t          dd| j                  d| j        iz  S )Nz=Your password must contain at least %(min_length)d character.z>Your password must contain at least %(min_length)d characters.rA   )r   rA   rB   s    r   r2   z$MinimumLengthValidator.get_help_texty   s0    KLO
 
 4?+	, 	,r   )r?   r   )__name__
__module____qualname____doc__rC   r$   r2   r   r   r   r>   r>   c   sU         % % % %   , , , , ,r   r>   c                 l    t          |           }|dz  |z  }t          |          }|d|z  k    o||k     S )a  
    Test that value is within a reasonable range of password.

    The following ratio calculations are based on testing SequenceMatcher like
    this:

    for i in range(0,6):
      print(10**i, SequenceMatcher(a='A', b='A'*(10**i)).quick_ratio())

    which yields:

    1 1.0
    10 0.18181818181818182
    100 0.019801980198019802
    1000 0.001998001998001998
    10000 0.00019998000199980003
    100000 1.999980000199998e-05

    This means a length_ratio of 10 should never yield a similarity higher than
    0.2, for 100 this is down to 0.02 and for 1000 it is 0.002. This can be
    calculated via 2 / length_ratio. As a result we avoid the potentially
    expensive sequence matching.
       
   )rI   )r%   max_similarityvaluepwd_lenlength_bound_similarity	value_lens         r   exceeds_maximum_length_ratiorY      sD    0 (mmG,q07:E

Ib9n$L5L)LLr   c                   0    e Zd ZdZdZedfdZddZd ZdS )	 UserAttributeSimilarityValidatora  
    Validate that the password is sufficiently different from the user's
    attributes.

    If no specific attributes are provided, look at a sensible list of
    defaults. Attributes that don't exist are ignored. Comparison is made to
    not only the full attribute value, but also its components, so that, for
    example, a password is validated against either part of an email address,
    as well as the full address.
    )username
first_name	last_nameemailgffffff?c                 L    || _         |dk     rt          d          || _        d S )Ng?z#max_similarity must be at least 0.1)user_attributes
ValueErrorrT   )rB   ra   rT   s      r   rC   z)UserAttributeSimilarityValidator.__init__   s2    .CBCCC,r   Nc                 L   |sd S |                                 }| j        D ]}t          ||d           }|rt          |t                    s,|                                 }t          j        d|          |gz   }|D ]}t          || j        |          rt          ||          
                                | j        k    ra	 t	          |j                            |          j                  }n# t          $ r |}Y nw xY wt          t!          d          dd|i          d S )Nz\W+)r.   bz4The password is too similar to the %(verbose_name)s.password_too_similarverbose_namerF   )lowerra   r0   
isinstancestrresplitrY   rT   r   quick_ratio_meta	get_fieldrf   r   r   _)	rB   r%   r&   attribute_namerU   value_lowervalue_parts
value_partrf   s	            r   r$   z)UserAttributeSimilarityValidator.validate   sr    	F>>##"2 	 	ND.$77E 
5# 6 6 ++--K(6;77;-GK)  
/d1:   #h*===IIKK*+ +6'* J00@@M( ( - 6 6 6'56)PQQ3 .=   +	 	s   ,C..C=<C=c                      t          d          S )NuH   Your password can’t be too similar to your other personal information.ro   rL   s    r   r2   z.UserAttributeSimilarityValidator.get_help_text   s    V
 
 	
r   r   )rM   rN   rO   rP   DEFAULT_USER_ATTRIBUTESrC   r$   r2   r   r   r   r[   r[      sd        	 	 O'>s - - - -   @
 
 
 
 
r   r[   c                   @    e Zd ZdZed             ZefdZddZd ZdS )CommonPasswordValidatora  
    Validate that the password is not a common password.

    The password is rejected if it occurs in a provided list of passwords,
    which may be gzipped. The list Django ships with contains 20000 common
    passwords (lowercased and deduplicated), created by Royce Williams:
    https://gist.github.com/roycewilliams/226886fd01572964e1431ac8afc999ce
    The password list must be lowercased to match the comparison in validate().
    c                 ^    t          t                                                    j        dz  S )Nzcommon-passwords.txt.gz)r   __file__resolveparentrL   s    r   DEFAULT_PASSWORD_LIST_PATHz2CommonPasswordValidator.DEFAULT_PASSWORD_LIST_PATH   s#    H~~%%''.1JJJr   c                 J   |t           j        u r| j        }	 t          j        |dd          5 }d |D             | _        d d d            d S # 1 swxY w Y   d S # t
          $ r> t          |          5 }d |D             | _        d d d            Y d S # 1 swxY w Y   Y d S w xY w)Nrtzutf-8)encodingc                 6    h | ]}|                                 S r   stripr8   xs     r   	<setcomp>z3CommonPasswordValidator.__init__.<locals>.<setcomp>        !7!7!7!''))!7!7!7r   c                 6    h | ]}|                                 S r   r   r   s     r   r   z3CommonPasswordValidator.__init__.<locals>.<setcomp>   r   r   )rx   r}   gzipopen	passwordsOSError)rB   password_list_pathfs      r   rC   z CommonPasswordValidator.__init__   sW   !8!SSS!%!@	8-tgFFF 8!!7!7Q!7!7!78 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 	8 	8 	8()) 8Q!7!7Q!7!7!78 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8	8sX   A A A AA AA B"3BB"B	B"B	B"!B"Nc                     |                                                                 | j        v rt          t	          d          d          d S )NzThis password is too common.password_too_commonrG   )rg   r   r   r   ro   rJ   s      r   r$   z CommonPasswordValidator.validate   sS    >>!!##t~55!011*    65r   c                      t          d          S )Nu2   Your password can’t be a commonly used password.ru   rL   s    r   r2   z%CommonPasswordValidator.get_help_text   s    EFFFr   r   )	rM   rN   rO   rP   r	   r}   rC   r$   r2   r   r   r   rx   rx      s~          K K _K +E 8 8 8 8   G G G G Gr   rx   c                        e Zd ZdZddZd ZdS )NumericPasswordValidatorz=
    Validate that the password is not entirely numeric.
    Nc                 j    |                                 rt          t          d          d          d S )Nz"This password is entirely numeric.password_entirely_numericr   )isdigitr   ro   rJ   s      r   r$   z!NumericPasswordValidator.validate  sF     	!6770   	 	r   c                      t          d          S )Nu*   Your password can’t be entirely numeric.ru   rL   s    r   r2   z&NumericPasswordValidator.get_help_text	  s    =>>>r   r   )rM   rN   rO   rP   r$   r2   r   r   r   r   r      sA            ? ? ? ? ?r   r   )NNr   )'	functoolsr   rj   difflibr   pathlibr   django.confr   django.core.exceptionsr   r   r   django.utils.functionalr	   r
   django.utils.htmlr   r   django.utils.module_loadingr   django.utils.translationr   ro   r   cacher   r   r*   r,   r4   r<   ri   "password_validators_help_text_htmlr>   rY   r[   rx   r   r   r   r   <module>r      sQ        				 # # # # # #                           
 : 9 9 9 9 9 9 9 ; ; ; ; ; ; ; ; 5 5 5 5 5 5 1 1 1 1 1 1 - - - - - - F F F   & & & &&	) 	) 	) 	)	 	 	 		H 	H 	H 	H &*T*Ms%S%S ", , , , , , , ,<M M M<7
 7
 7
 7
 7
 7
 7
 7
t!G !G !G !G !G !G !G !GH? ? ? ? ? ? ? ? ? ?r   