
    Dvg                     l    d dl m Z  d dlmZ d dlmZmZ d dlmZmZ  G d d          Z	 e	            Z
dS )    )datetime)settings)constant_time_comparesalted_hmac)base36_to_intint_to_base36c                       e Zd ZdZdZdZdZdZd Zd Z	d Z
 ee	e
          Zd Zd Z eee          Zd	 Zd
 Zd Zd Zd Zd ZdS )PasswordResetTokenGeneratorza
    Strategy object used to generate and check tokens for the password
    reset mechanism.
    z6django.contrib.auth.tokens.PasswordResetTokenGeneratorNc                 "    | j         pd| _         d S )Nsha256)	algorithmselfs    W/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/auth/tokens.py__init__z$PasswordResetTokenGenerator.__init__   s    38    c                 (    | j         pt          j        S N)_secretr   
SECRET_KEYr   s    r   _get_secretz'PasswordResetTokenGenerator._get_secret   s    |2x22r   c                     || _         d S r   )r   )r   secrets     r   _set_secretz'PasswordResetTokenGenerator._set_secret   s    r   c                 6    | j         t          j        S | j         S r   )_secret_fallbacksr   SECRET_KEY_FALLBACKSr   s    r   _get_fallbacksz*PasswordResetTokenGenerator._get_fallbacks   s    !)00%%r   c                     || _         d S r   )r   )r   	fallbackss     r   _set_fallbacksz*PasswordResetTokenGenerator._set_fallbacks#   s    !*r   c                     |                      ||                     |                                           | j                  S )zi
        Return a token that can be used once to do a password reset
        for the given user.
        )_make_token_with_timestamp_num_seconds_nowr   )r   users     r   
make_tokenz&PasswordResetTokenGenerator.make_token(   s=    
 ..diikk**K
 
 	
r   c                    |r|sdS 	 |                     d          \  }}n# t          $ r Y dS w xY w	 t          |          }n# t          $ r Y dS w xY w| j        g| j        D ])}t          |                     |||          |          r n*dS |                     |                                           |z
  t          j
        k    rdS dS )zP
        Check that a password reset token is correct for a given user.
        F-T)split
ValueErrorr   r   secret_fallbacksr   r#   r$   r%   r   PASSWORD_RESET_TIMEOUT)r   r&   tokents_b36_tsr   s          r   check_tokenz'PasswordResetTokenGenerator.check_token3   s     	 	5	C((IFAA 	 	 	55		v&&BB 	 	 	55	 {;T%:; 	 	F$//b&AA   	 5 diikk**R/83RRR5ts   ! 
//A 
AAc                     t          |          }t          | j        |                     ||          || j                                                  d d d         }|d|S )N)r   r      r)   )r   r   key_salt_make_hash_valuer   	hexdigest)r   r&   	timestampr   r/   hash_strings         r   r#   z6PasswordResetTokenGenerator._make_token_with_timestampT   sq     y))!M!!$	22n	
 
 

 )++CaC
 !&&++..r   c                     |j         dn|j                             dd          }|                                }t          ||d          pd}|j         |j         | | | S )a  
        Hash the user's primary key, email (if available), and some user state
        that's sure to change after a password reset to produce a token that is
        invalidated when it's used:
        1. The password field will change upon a password reset (even if the
           same password is chosen, due to password salting).
        2. The last_login field will usually be updated very shortly after
           a password reset.
        Failing those things, settings.PASSWORD_RESET_TIMEOUT eventually
        invalidates the token.

        Running this data through salted_hmac() prevents password cracking
        attempts using the reset token, provided the secret isn't compromised.
        N r   )microsecondtzinfo)
last_loginreplaceget_email_field_namegetattrpkpassword)r   r&   r8   login_timestampemail_fieldemails         r   r6   z,PasswordResetTokenGenerator._make_hash_valueb   s}    & & B((Qt(DD 	
 //11k2..4"'M4=M/M9MeMMMr   c                 h    t          |t          ddd          z
                                            S )Ni     )intr   total_seconds)r   dts     r   r$   z(PasswordResetTokenGenerator._num_seconds|   s-    B$1---<<>>???r   c                 (    t          j                    S r   )r   nowr   s    r   r%   z PasswordResetTokenGenerator._now   s    |~~r   )__name__
__module____qualname____doc__r5   r   r   r   r   r   r   propertyr   r   r!   r,   r'   r2   r#   r6   r$   r%    r   r   r
   r
      s	        
 HHIG4 4 43 3 3   Xk;//F& & &
+ + +  x??	
 	
 	
  B/ / /N N N4@ @ @    r   r
   N)r   django.confr   django.utils.cryptor   r   django.utils.httpr   r   r
   default_token_generatorrS   r   r   <module>rX      s                      B B B B B B B B : : : : : : : :y y y y y y y yx 6577   r   