
    +hv                     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                   l    e 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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    ^/var/www/html/e360mart/e360mart_env/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                 x    |                      ||                     |                                                     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_now)r   users     r   
make_tokenz&PasswordResetTokenGenerator.make_token   s0    
 ..tT5F5Ftyy{{5S5STTTr   c                 l   |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t          |                     ||          |          s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   r   r   r   r   PASSWORD_RESET_TIMEOUT)r   r   tokents_b36_tss         r   check_tokenz'PasswordResetTokenGenerator.check_token#   s      	 	5	C((IFAA 	 	 	55		v&&BB 	 	 	55	 %T%D%DT2%N%NPUVV 	5 diikk**R/83RRR5ts   ! 
//A 
AAc                     t          |          }t          | j        |                     ||          | j        | j                                                  d d d         }|d|S )N)r   r      r"   )r   r   key_salt_make_hash_valuer   r   	hexdigest)r   r   	timestampr'   hash_strings        r   r   z6PasswordResetTokenGenerator._make_token_with_timestamp>   sr     y))!M!!$	22;n	
 
 

 )++ccc !&&++..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   r0   login_timestampemail_fieldemails         r   r.   z,PasswordResetTokenGenerator._make_hash_valueJ   sv    " !% 7""T_=T=Tabko=T=p=p//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._nowc   s    |~~r   )__name__
__module____qualname____doc__r-   r   r   r   r   r   propertyr   r    r*   r   r.   r   r    r   r   r
   r
      s          HHIG4 4 43 3 3   Xk;//FU U U  6
/ 
/ 
/N N N,@ @ @    r   r
   N)r   django.confr   django.utils.cryptor   r   django.utils.httpr   r   r
   default_token_generatorrK   r   r   <module>rP      s                      B B B B B B B B : : : : : : : :] ] ] ] ] ] ] ]@ 6577   r   