o
    Mf                     @   sT   d dl m Z mZ d dlmZ d dlmZmZ d dlmZm	Z	 G dd dZ
e
 ZdS )    )datetimetime)settings)constant_time_comparesalted_hmac)base36_to_intint_to_base36c                   @   sV   e Zd ZdZdZdZdZdd Zdd Zdd	 Z	dddZ
dd Zdd Zdd ZdS )PasswordResetTokenGeneratorza
    Strategy object used to generate and check tokens for the password
    reset mechanism.
    z6django.contrib.auth.tokens.PasswordResetTokenGeneratorNc                 C   s    | j ptj| _ | jptj| _d S N)secretr   
SECRET_KEY	algorithmDEFAULT_HASHING_ALGORITHMself r   \/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/django/contrib/auth/tokens.py__init__   s   z$PasswordResetTokenGenerator.__init__c                 C   s   |  || |  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   userr   r   r   
make_token   s   z&PasswordResetTokenGenerator.make_tokenc                 C   s   |r|sdS z| d\}}t|dk }W n
 ty   Y dS w zt|}W n
 ty0   Y dS w t| |||sGt| j||dd|sGdS |  }|rb|d9 }|t|t	|
 tj  7 }| || tjkrndS dS )zP
        Check that a password reset token is correct for a given user.
        F-   T)legacyiQ )splitlen
ValueErrorr   r   r   r   intr   combinedater   mintotal_secondsr   r   PASSWORD_RESET_TIMEOUT)r   r   tokents_b36_legacy_tokentsnowr   r   r   check_token   s4   "z'PasswordResetTokenGenerator.check_tokenFc                 C   sH   t |}t| j| ||| j|rdn| jd d d d }d||f S )Nsha1)r   r      z%s-%s)r   r   key_salt_make_hash_valuer   r   	hexdigest)r   r   	timestampr   r&   hash_stringr   r   r   r   H   s   
	z6PasswordResetTokenGenerator._make_token_with_timestampc                 C   sR   |j du rdn|j jd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   r1   login_timestampemail_fieldemailr   r   r   r/   W   s   z,PasswordResetTokenGenerator._make_hash_valuec                 C   s   t |tddd  S )Ni     )r   r   r#   )r   dtr   r   r   r   m   s   z(PasswordResetTokenGenerator._num_secondsc                 C   s   t  S r
   )r   r*   r   r   r   r   r   p   s   z PasswordResetTokenGenerator._now)F)__name__
__module____qualname____doc__r.   r   r   r   r   r+   r   r/   r   r   r   r   r   r   r	      s    
*r	   N)r   r   django.confr   django.utils.cryptor   r   django.utils.httpr   r   r	   default_token_generatorr   r   r   r   <module>   s    
m