Ë
    ¹ûàgŽ$  ã                   óJ  — 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 j2                  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&y)é    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© ó    úe/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/django/contrib/auth/password_validation.pyÚget_default_password_validatorsr      s   € ä"¤8×#DÑ#DÓEÐEr   c                 óÄ   — g }| D ]8  }	 t        |d   «      }|j                   |di |j	                  di «      ¤Ž«       Œ: |S # t        $ r d}t        ||d   z  «      ‚w xY w)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ˆ	ð	@Ü! )¨FÑ"3Ó4ˆEð 	×Ñ™%Ñ? )§-¡-°	¸2Ó">Ñ?Õ@ð	Að Ðøô ò 	@ð4ð ô ' s¨Y°vÑ->Ñ'>Ó?Ð?ð	@ús   ‰AÁAc                 ó¼   — g }|€
t        «       }|D ]  }	 |j                  | |«       Œ |rt        |«      ‚y# t        $ r}|j                  |«       Y d}~ŒEd}~ww xY w)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*   )   sr   € ð €FØÐ"Ü=Ó?ÐØ(ò !ˆ	ð	!Ø×Ñ˜x¨Õ.ð!ñ
 Ü˜fÓ%Ð%ð øô ò 	!Ø�M‰M˜%× Ñ ûð	!ús   •7·	AÁ AÁAc                 óX   — |€
t        «       }|D ]  }t        |dd„ «      } || |«       Œ y)zy
    Inform all validators that have implemented a password_changed() method
    that the password has been changed.
    NÚpassword_changedc                   ó   — y r   r   )Úas    r   ú<lambda>z"password_changed.<locals>.<lambda>D   s   � r   )r   Úgetattr)r%   r&   r'   r    r,   s        r   r,   r,   <   s<   € ð
 Ð"Ü=Ó?ÐØ(ò )ˆ	Ü" 9Ð.@Á/ÓRÐÙ˜ 4Õ(ñ)r   c                 ón   — g }| €
t        «       } | D ]!  }|j                  |j                  «       «       Œ# |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   sD   € ð €JØÐ"Ü=Ó?ÐØ(ò 5ˆ	Ø×Ñ˜)×1Ñ1Ó3Õ4ð5àÐr   c                 ó`   — t        | «      }t        ddd„ |D «       «      }|rt        d|«      S 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–— Œ	 y ­wr   r   )Ú.0Ú	help_texts     r   ú	<genexpr>z6_password_validators_help_text_html.<locals>.<genexpr>[   s   è ø€ ÒE¨Y˜YœLÑEùs   ‚z<ul>{}</ul>)r4   r   r   )r'   r3   Ú
help_itemss      r   Ú#_password_validators_help_text_htmlr<   T   s=   € ô
 0Ð0CÓD€JÜ!Ø
ˆMÑE¸*ÔEó€Jñ 6@Œ;�} jÓ1ÐGÀRÐGr   c                   ó&   — e Zd ZdZdd„Zdd„Zd„ Zy)ÚMinimumLengthValidatorz<
    Validate that the password is of a minimum length.
    c                 ó   — || _         y r   )Ú
min_length)Úselfr@   s     r   Ú__init__zMinimumLengthValidator.__init__h   s	   € Ø$ˆ�r   Nc                 ó’   — t        |«      | j                  k  r/t        t        dd| j                  «      dd| j                  i¬«      ‚y )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_shortr@   ©ÚcodeÚparams)Úlenr@   r   r   ©rA   r%   r&   s      r   r$   zMinimumLengthValidator.validatek   sN   € Üˆx‹=˜4Ÿ?™?Ò*Ü!Üð0ð1à—O‘Oóð *Ø$ d§o¡oÐ6ô
ð 
ð +r   c                 óN   — 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.r@   )r   r@   ©rA   s    r   r2   z$MinimumLengthValidator.get_help_texty   s/   € ÜØKØLØ�O‰Oó
ð ˜4Ÿ?™?Ð+ñ	,ð 	,r   )é   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rB   r$   r2   r   r   r   r>   r>   c   s   „ ñó%óó,r   r>   c                 ó\   — t        | «      }|dz  |z  }t        |«      }|d|z  k\  xr ||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.
    é   é
   )rH   )r%   Úmax_similarityÚvalueÚpwd_lenÚlength_bound_similarityÚ	value_lens         r   Úexceeds_maximum_length_ratiorY   �   s@   € ô0 �(‹m€GØ,¨qÑ0°7Ñ:ÐÜ�E“
€IØ�b˜9‘nÑ$ÒL¨Ð5LÑ)LÐLr   c                   ó.   — e Zd ZdZdZedfd„Zdd„Zd„ Zy)	Ú 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                 ó@   — || _         |dk  rt        d«      ‚|| _        y )Ngš™™™™™¹?z#max_similarity must be at least 0.1)Úuser_attributesÚ
ValueErrorrT   )rA   ra   rT   s      r   rB   z)UserAttributeSimilarityValidator.__init__­   s&   € Ø.ˆÔØ˜CÒÜÐBÓCÐCØ,ˆÕr   Nc                 ó   — |sy |j                  «       }| j                  D ]Û  }t        ||d «      }|rt        |t        «      sŒ#|j                  «       }t        j                  d|«      |gz   }|D ]Š  }t        || j                  |«      rŒt        ||¬«      j                  «       | j                  k\  sŒD	 t	        |j                  j                  |«      j                  «      }t        t!        d«      dd|i¬«      ‚ ŒÝ y # t        $ r |}Y Œ*w xY w)Nz\W+)r.   Úbz4The password is too similar to the %(verbose_name)s.Úpassword_too_similarÚverbose_namerE   )Úlowerra   r0   Ú
isinstanceÚstrÚreÚsplitrY   rT   r   Úquick_ratioÚ_metaÚ	get_fieldrf   r   r   Ú_)	rA   r%   r&   Úattribute_namerU   Úvalue_lowerÚvalue_partsÚ
value_partrf   s	            r   r$   z)UserAttributeSimilarityValidator.validate³   s  € ÙØà—>‘>Ó#ˆØ"×2Ñ2ò 	ˆNÜ˜D .°$Ó7ˆEÙ¤
¨5´#Ô 6ØØŸ+™+›-ˆKÜŸ(™( 6¨;Ó7¸;¸-ÑGˆKØ)ò �
Ü/Ø˜d×1Ñ1°:ôð ä# h°*Ô=×IÑIÓKØ×*Ñ*ó+ð6Ü'*Ø ŸJ™J×0Ñ0°Ó@×MÑMó(˜ô
 *ÜÐPÓQØ3Ø .°Ð=ôð ññ	øô& -ò 6Ø'5šð6ús   Â4.C?Ã?DÄDc                 ó   — t        d«      S )NuH   Your password canâ€™t be too similar to your other personal information.©ro   rK   s    r   r2   z.UserAttributeSimilarityValidator.get_help_textÓ   s   € ÜØVó
ð 	
r   r   )rM   rN   rO   rP   ÚDEFAULT_USER_ATTRIBUTESrB   r$   r2   r   r   r   r[   r[   Ÿ   s%   „ ñ	ð OÐà'>Èsó -óó@
r   r[   c                   ó8   — e Zd ZdZed„ «       Zefd„Zdd„Zd„ Zy)Ú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                 óV   — t        t        «      j                  «       j                  dz  S )Nzcommon-passwords.txt.gz)r   Ú__file__ÚresolveÚparentrK   s    r   ÚDEFAULT_PASSWORD_LIST_PATHz2CommonPasswordValidator.DEFAULT_PASSWORD_LIST_PATHä   s!   € ä”H‹~×%Ñ%Ó'×.Ñ.Ð1JÑJÐJr   c                 óž  — |t         j                  u r| j                  }	 t        j                  |dd¬«      5 }|D �ch c]  }|j	                  «       ’Œ c}| _        d d d «       y c c}w # 1 sw Y   y xY w# t        $ rM t        |«      5 }|D �ch c]  }|j	                  «       ’Œ nc c}w c}| _        d d d «       Y y # 1 sw Y   Y y xY ww xY w)NÚrtzutf-8)Úencoding)rx   r}   ÚgzipÚopenÚstripÚ	passwordsÚOSError)rA   Úpassword_list_pathÚfÚxs       r   rB   z CommonPasswordValidator.__init__è   s³   € ØÔ!8×!SÑ!SÑSØ!%×!@Ñ!@Ðð	8Ü—‘Ð-¨t¸gÔFð 8È!Ø56Ö!7° !§'¡'¥)Ò!7�”÷8ð 8ùÚ!7÷8ð 8ûäò 	8ÜÐ(Ó)ð 8¨QØ56Ö!7° !§'¡'¥)Ñ!7ùÔ!7�”÷8÷ 8ó 8úð	8úsc    A6 ¸A*½A%ÁA*ÁA6 Á%A*Á*A3Á/A6 Á3A6 Á6CÂ
B>ÂB'Â&B>Â4CÂ>C	ÃCÃCNc                 ó„   — |j                  «       j                  «       | j                  v rt        t	        d«      d¬«      ‚y )NzThis password is too common.Úpassword_too_common©rF   )rg   rƒ   r„   r   ro   rI   s      r   r$   z CommonPasswordValidator.validateò   s<   € Ø�>‰>Ó×!Ñ!Ó# t§~¡~Ñ5Ü!ÜÐ0Ó1Ø*ôð ð 6r   c                 ó   — t        d«      S )Nu2   Your password canâ€™t be a commonly used password.ru   rK   s    r   r2   z%CommonPasswordValidator.get_help_textù   s   € ÜÐEÓFÐFr   r   )	rM   rN   rO   rP   r	   r}   rB   r$   r2   r   r   r   rx   rx   Ù   s3   „ ñð ñKó ðKð +Eó 8óóGr   rx   c                   ó   — e Zd ZdZdd„Zd„ Zy)ÚNumericPasswordValidatorz=
    Validate that the password is not entirely numeric.
    Nc                 óP   — |j                  «       rt        t        d«      d¬«      ‚y )Nz"This password is entirely numeric.Úpassword_entirely_numericr‹   )Úisdigitr   ro   rI   s      r   r$   z!NumericPasswordValidator.validate  s,   € Ø×ÑÔÜ!ÜÐ6Ó7Ø0ôð ð r   c                 ó   — t        d«      S )Nu*   Your password canâ€™t be entirely numeric.ru   rK   s    r   r2   z&NumericPasswordValidator.get_help_text	  s   € ÜÐ=Ó>Ð>r   r   )rM   rN   rO   rP   r$   r2   r   r   r   rŽ   rŽ   ý   s   „ ñóó?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ž      s¨   ðÛ Û Û 	Ý #Ý å  ÷ñ ÷
 :ß ;Ý 5Ý 1Ý -ð ‡�ñFó ðFòó &ó&	)ó	ó	Hñ &*Ð*MÈsÓ%SÐ "÷,ñ ,ò<M÷<7
ñ 7
÷t!Gñ !G÷H?ò ?r   